Skip to content

Commit c2fcd4c

Browse files
committed
Check traits for built-in bounds in impls
1 parent 0c73e5f commit c2fcd4c

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/libcore/ops.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
*
5656
*/
5757

58+
use kinds::Sized;
59+
5860
/**
5961
*
6062
* 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> {
700702
* ```
701703
*/
702704
#[lang="deref"]
703-
pub trait Deref<Result> {
705+
pub trait Deref<Sized? Result> {
704706
/// The method called to dereference a value
705707
fn deref<'a>(&'a self) -> &'a Result;
706708
}
@@ -740,7 +742,7 @@ pub trait Deref<Result> {
740742
* ```
741743
*/
742744
#[lang="deref_mut"]
743-
pub trait DerefMut<Result>: Deref<Result> {
745+
pub trait DerefMut<Sized? Result>: Deref<Result> {
744746
/// The method called to mutably dereference a value
745747
fn deref_mut<'a>(&'a mut self) -> &'a mut Result;
746748
}

src/librustc/middle/kind.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ fn check_item(cx: &mut Context, item: &Item) {
199199
cx,
200200
item.span,
201201
&*trait_ref);
202+
203+
let trait_def = ty::lookup_trait_def(cx.tcx, trait_ref.def_id);
204+
for (ty, type_param_def) in trait_ref.substs.types
205+
.iter()
206+
.zip(trait_def.generics
207+
.types
208+
.iter()) {
209+
check_typaram_bounds(cx, item.span, *ty, type_param_def);
210+
}
202211
}
203212
}
204213
}

src/test/compile-fail/unsized3.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,18 @@ fn f9<Sized? X>(x1: Box<S<X>>, x2: Box<E<X>>) {
5757
//~^ ERROR instantiating a type parameter with an incompatible type
5858
}
5959

60-
// I would like these to fail eventually.
61-
/*
6260
// impl - bounded
6361
trait T1<Z: T> {
6462
}
6563
struct S3<Sized? Y>;
66-
impl<Sized? X: T> T1<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type
64+
impl<Sized? X: T> T1<X> for S3<X> { //~ ERROR instantiating a type parameter with an incompatible
6765
}
6866

6967
// impl - unbounded
7068
trait T2<Z> {
7169
}
72-
impl<Sized? X> T2<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type `X
73-
*/
70+
impl<Sized? X> T2<X> for S3<X> { //~ ERROR instantiating a type parameter with an incompatible type
71+
}
7472

7573
// impl - struct
7674
trait T3<Sized? Z> {

0 commit comments

Comments
 (0)