Skip to content

Commit d5f72d2

Browse files
Fix ICE when querying DefId on Def::Err.
1 parent ac919fc commit d5f72d2

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Diff for: src/librustc_typeck/collect.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1724,16 +1724,15 @@ fn add_unsized_bound<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
17241724
match unbound {
17251725
Some(ref tpb) => {
17261726
// FIXME(#8559) currently requires the unbound to be built-in.
1727-
let trait_def_id = tcx.expect_def(tpb.ref_id).def_id();
1728-
match kind_id {
1729-
Ok(kind_id) if trait_def_id != kind_id => {
1727+
if let Ok(kind_id) = kind_id {
1728+
let trait_def = tcx.expect_def(tpb.ref_id);
1729+
if trait_def != Def::Trait(kind_id) {
17301730
tcx.sess.span_warn(span,
17311731
"default bound relaxed for a type parameter, but \
17321732
this does nothing because the given bound is not \
17331733
a default. Only `?Sized` is supported");
17341734
tcx.try_add_builtin_trait(kind_id, bounds);
17351735
}
1736-
_ => {}
17371736
}
17381737
}
17391738
_ if kind_id.is_ok() => {

Diff for: 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)