]> git.lizzy.rs Git - rust.git/commitdiff
Check traits for built-in bounds in impls
authorNick Cameron <ncameron@mozilla.com>
Fri, 5 Sep 2014 05:10:32 +0000 (17:10 +1200)
committerNick Cameron <ncameron@mozilla.com>
Mon, 8 Sep 2014 22:41:27 +0000 (10:41 +1200)
src/libcore/ops.rs
src/librustc/middle/kind.rs
src/test/compile-fail/unsized3.rs

index 836285bc3135ad8e0bbd1dac18695439d2b89a5b..94febf0363594d543ba05658d2a154e67c3273ac 100644 (file)
@@ -55,6 +55,8 @@
  *
  */
 
+use kinds::Sized;
+
 /**
  *
  * The `Drop` trait is used to run some code when a value goes out of scope. This
@@ -700,7 +702,7 @@ pub trait IndexMut<Index,Result> {
  * ```
  */
 #[lang="deref"]
-pub trait Deref<Result> {
+pub trait Deref<Sized? Result> {
     /// The method called to dereference a value
     fn deref<'a>(&'a self) -> &'a Result;
 }
@@ -740,7 +742,7 @@ pub trait Deref<Result> {
  * ```
  */
 #[lang="deref_mut"]
-pub trait DerefMut<Result>: Deref<Result> {
+pub trait DerefMut<Sized? Result>: Deref<Result> {
     /// The method called to mutably dereference a value
     fn deref_mut<'a>(&'a mut self) -> &'a mut Result;
 }
index e556c5a59c224696dcb3540358084453a8c0e4d0..e8b0afa98c2d0487c78f0f2d54ae4e0f5a723adb 100644 (file)
@@ -199,6 +199,15 @@ fn check_item(cx: &mut Context, item: &Item) {
                                     cx,
                                     item.span,
                                     &*trait_ref);
+
+                                let trait_def = ty::lookup_trait_def(cx.tcx, trait_ref.def_id);
+                                for (ty, type_param_def) in trait_ref.substs.types
+                                                                  .iter()
+                                                                  .zip(trait_def.generics
+                                                                                .types
+                                                                                .iter()) {
+                                    check_typaram_bounds(cx, item.span, *ty, type_param_def);
+                                }
                             }
                         }
                     }
index cf42e79b3941e23bd0c614854d3fb7d55b8c00ae..f71afeb1b308f5f15080de2913b6f2570e11e63c 100644 (file)
@@ -57,20 +57,18 @@ fn f9<Sized? X>(x1: Box<S<X>>, x2: Box<E<X>>) {
     //~^ ERROR instantiating a type parameter with an incompatible type
 }
 
-// I would like these to fail eventually.
-/*
 // impl - bounded
 trait T1<Z: T> {
 }
 struct S3<Sized? Y>;
-impl<Sized? X: T> T1<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type
+impl<Sized? X: T> T1<X> for S3<X> { //~ ERROR instantiating a type parameter with an incompatible
 }
 
 // impl - unbounded
 trait T2<Z> {
 }
-impl<Sized? X> T2<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type `X
-*/
+impl<Sized? X> T2<X> for S3<X> { //~ ERROR instantiating a type parameter with an incompatible type
+}
 
 // impl - struct
 trait T3<Sized? Z> {