Skip to content

Commit

Permalink
Rollup merge of rust-lang#37564 - Mark-Simulacrum:sized-ice, r=eddyb
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jonathan Turner authored Nov 5, 2016
2 parents 9296ed9 + d5f72d2 commit 113a2b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,16 +1724,15 @@ fn add_unsized_bound<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
match unbound {
Some(ref tpb) => {
// FIXME(#8559) currently requires the unbound to be built-in.
let trait_def_id = tcx.expect_def(tpb.ref_id).def_id();
match kind_id {
Ok(kind_id) if trait_def_id != kind_id => {
if let Ok(kind_id) = kind_id {
let trait_def = tcx.expect_def(tpb.ref_id);
if trait_def != Def::Trait(kind_id) {
tcx.sess.span_warn(span,
"default bound relaxed for a type parameter, but \
this does nothing because the given bound is not \
a default. Only `?Sized` is supported");
tcx.try_add_builtin_trait(kind_id, bounds);
}
_ => {}
}
}
_ if kind_id.is_ok() => {
Expand Down
16 changes: 16 additions & 0 deletions src/test/compile-fail/issue-37534.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

struct Foo<T: ?Hash> { }
//~^ ERROR trait `Hash` is not in scope [E0405]
//~^^ ERROR parameter `T` is never used [E0392]
//~^^^ WARN default bound relaxed for a type parameter, but this does nothing

fn main() { }

0 comments on commit 113a2b4

Please sign in to comment.