From c2fcd4ca723426c9d708a4cc49da873124e44891 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 5 Sep 2014 17:10:32 +1200 Subject: [PATCH] Check traits for built-in bounds in impls --- src/libcore/ops.rs | 6 ++++-- src/librustc/middle/kind.rs | 9 +++++++++ src/test/compile-fail/unsized3.rs | 8 +++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 836285bc3135..94febf036359 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -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 { * ``` */ #[lang="deref"] -pub trait Deref { +pub trait Deref { /// The method called to dereference a value fn deref<'a>(&'a self) -> &'a Result; } @@ -740,7 +742,7 @@ pub trait Deref { * ``` */ #[lang="deref_mut"] -pub trait DerefMut: Deref { +pub trait DerefMut: Deref { /// The method called to mutably dereference a value fn deref_mut<'a>(&'a mut self) -> &'a mut Result; } diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index e556c5a59c22..e8b0afa98c2d 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -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); + } } } } diff --git a/src/test/compile-fail/unsized3.rs b/src/test/compile-fail/unsized3.rs index cf42e79b3941..f71afeb1b308 100644 --- a/src/test/compile-fail/unsized3.rs +++ b/src/test/compile-fail/unsized3.rs @@ -57,20 +57,18 @@ fn f9(x1: Box>, x2: Box>) { //~^ ERROR instantiating a type parameter with an incompatible type } -// I would like these to fail eventually. -/* // impl - bounded trait T1 { } struct S3; -impl T1 for S3 { //ERROR instantiating a type parameter with an incompatible type +impl T1 for S3 { //~ ERROR instantiating a type parameter with an incompatible } // impl - unbounded trait T2 { } -impl T2 for S3 { //ERROR instantiating a type parameter with an incompatible type `X -*/ +impl T2 for S3 { //~ ERROR instantiating a type parameter with an incompatible type +} // impl - struct trait T3 {