Skip to content

Commit 806b5e1

Browse files
committed
auto merge of #17008 : nick29581/rust/impl2, r=pcwalton
r? (btw, the change to Deref is one we would like to make at some point anyway, but it is needed here to keep some tests passing)
2 parents 67b97ab + 680c821 commit 806b5e1

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
@@ -197,6 +197,15 @@ fn check_item(cx: &mut Context, item: &Item) {
197197
cx,
198198
item.span,
199199
&*trait_ref);
200+
201+
let trait_def = ty::lookup_trait_def(cx.tcx, trait_ref.def_id);
202+
for (ty, type_param_def) in trait_ref.substs.types
203+
.iter()
204+
.zip(trait_def.generics
205+
.types
206+
.iter()) {
207+
check_typaram_bounds(cx, item.span, *ty, type_param_def);
208+
}
200209
}
201210
}
202211

src/test/compile-fail/unsized3.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,18 @@ fn f9<Sized? X>(x1: Box<S<X>>, x2: Box<E<X>>) {
5555
f5(&(32i, *x2)); //~ERROR instantiating a type parameter with an incompatible type `(int,E<X>)`,
5656
}
5757

58-
// I would like these to fail eventually.
59-
/*
6058
// impl - bounded
6159
trait T1<Z: T> {
6260
}
6361
struct S3<Sized? Y>;
64-
impl<Sized? X: T> T1<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type
62+
impl<Sized? X: T> T1<X> for S3<X> { //~ ERROR instantiating a type parameter with an incompatible
6563
}
6664

6765
// impl - unbounded
6866
trait T2<Z> {
6967
}
70-
impl<Sized? X> T2<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type `X
71-
*/
68+
impl<Sized? X> T2<X> for S3<X> { //~ ERROR instantiating a type parameter with an incompatible type
69+
}
7270

7371
// impl - struct
7472
trait T3<Sized? Z> {

0 commit comments

Comments
 (0)