Skip to content

Commit 0c85ad8

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#37564 - Mark-Simulacrum:sized-ice, r=eddyb
Fix ICE when querying DefId on Def::Err. Also moves computations into check that `kind_id` is `Ok(_)`, which is in theory an optimization, though I expect it's minor. Fixes rust-lang#37534. r? @eddyb.
2 parents fbcb057 + d5f72d2 commit 0c85ad8

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/librustc_typeck/collect.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1594,16 +1594,15 @@ fn add_unsized_bound<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
15941594
match unbound {
15951595
Some(ref tpb) => {
15961596
// FIXME(#8559) currently requires the unbound to be built-in.
1597-
let trait_def_id = tcx.expect_def(tpb.ref_id).def_id();
1598-
match kind_id {
1599-
Ok(kind_id) if trait_def_id != kind_id => {
1597+
if let Ok(kind_id) = kind_id {
1598+
let trait_def = tcx.expect_def(tpb.ref_id);
1599+
if trait_def != Def::Trait(kind_id) {
16001600
tcx.sess.span_warn(span,
16011601
"default bound relaxed for a type parameter, but \
16021602
this does nothing because the given bound is not \
16031603
a default. Only `?Sized` is supported");
16041604
tcx.try_add_builtin_trait(kind_id, bounds);
16051605
}
1606-
_ => {}
16071606
}
16081607
}
16091608
_ if kind_id.is_ok() => {

src/test/compile-fail/issue-37534.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Foo<T: ?Hash> { }
12+
//~^ ERROR trait `Hash` is not in scope [E0405]
13+
//~^^ ERROR parameter `T` is never used [E0392]
14+
//~^^^ WARN default bound relaxed for a type parameter, but this does nothing
15+
16+
fn main() { }

0 commit comments

Comments
 (0)