]> git.lizzy.rs Git - rust.git/commitdiff
Check concrete type in impls with no trait
authorNick Cameron <ncameron@mozilla.com>
Fri, 5 Sep 2014 02:38:37 +0000 (14:38 +1200)
committerNick Cameron <ncameron@mozilla.com>
Fri, 5 Sep 2014 02:38:37 +0000 (14:38 +1200)
closes #16955

src/librustc/middle/kind.rs
src/test/compile-fail/trait-bounds-on-structs-and-enums.rs
src/test/compile-fail/unsized3.rs

index 5814b6b02fe382ee6e4225bd0c7777b5e958466b..99c1d65d2b5b45356a0f552695e1f3dd451de809 100644 (file)
@@ -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());
index 537656d1479e6c7fbd15ede07d5db4d0dbfe2060..ba035dd2c6f195be6082cc9637c7e2146b3cadaf 100644 (file)
@@ -28,7 +28,8 @@ fn kaboom(y: Bar<f32>) {}
 //~^ ERROR failed to find an implementation
 //~^^ ERROR instantiating a type parameter with an incompatible type
 
-impl<T> Foo<T> {
+impl<T> Foo<T> { //~ ERROR failed to find an implementation
+//~^ ERROR instantiating a type parameter with an incompatible type
     fn uhoh() {}
 }
 
index 4f1f21f6c0e276e684f00c19228822767285c6f2..50e109b9934711a6b9b4fbde3bd0a09c8ef06b8e 100644 (file)
@@ -76,6 +76,8 @@ trait T3<Sized? Z> {
 struct S4<Y>;
 impl<Sized? X> T3<X> for S4<X> { //~ ERROR instantiating a type parameter with an incompatible type
 }
+impl<Sized? X> S4<X> { //~ ERROR instantiating a type parameter with an incompatible type
+}
 
 
 pub fn main() {