diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 5814b6b02fe..99c1d65d2b5 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -175,9 +175,7 @@ fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_t fn check_item(cx: &mut Context, item: &Item) { if !attr::contains_name(item.attrs.as_slice(), "unsafe_destructor") { match item.node { - ItemImpl(_, Some(ref trait_ref), ref self_type, _) => { - check_impl_of_trait(cx, item, trait_ref, &**self_type); - + ItemImpl(_, ref trait_ref, ref self_type, _) => { let parameter_environment = ParameterEnvironment::for_item(cx.tcx, item.id); cx.parameter_environments.push(parameter_environment); @@ -188,16 +186,23 @@ fn check_item(cx: &mut Context, item: &Item) { item.span, ty::node_id_to_type(cx.tcx, item.id)); - // Check bounds on the trait ref. - match ty::impl_trait_ref(cx.tcx, - ast_util::local_def(item.id)) { - None => {} - Some(trait_ref) => { - check_bounds_on_structs_or_enums_in_trait_ref( - cx, - item.span, - &*trait_ref); + match trait_ref { + &Some(ref trait_ref) => { + check_impl_of_trait(cx, item, trait_ref, &**self_type); + + // Check bounds on the trait ref. + match ty::impl_trait_ref(cx.tcx, + ast_util::local_def(item.id)) { + None => {} + Some(trait_ref) => { + check_bounds_on_structs_or_enums_in_trait_ref( + cx, + item.span, + &*trait_ref); + } + } } + &None => {} } drop(cx.parameter_environments.pop()); diff --git a/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs b/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs index 537656d1479..ba035dd2c6f 100644 --- a/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs +++ b/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs @@ -28,7 +28,8 @@ fn kaboom(y: Bar) {} //~^ ERROR failed to find an implementation //~^^ ERROR instantiating a type parameter with an incompatible type -impl Foo { +impl Foo { //~ ERROR failed to find an implementation +//~^ ERROR instantiating a type parameter with an incompatible type fn uhoh() {} } diff --git a/src/test/compile-fail/unsized3.rs b/src/test/compile-fail/unsized3.rs index 4f1f21f6c0e..50e109b9934 100644 --- a/src/test/compile-fail/unsized3.rs +++ b/src/test/compile-fail/unsized3.rs @@ -76,6 +76,8 @@ trait T3 { struct S4; impl T3 for S4 { //~ ERROR instantiating a type parameter with an incompatible type } +impl S4 { //~ ERROR instantiating a type parameter with an incompatible type +} pub fn main() {