Skip to content

Check traits for built-in bounds in impls #17008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
*
*/

use kinds::Sized;

/**
*
* The `Drop` trait is used to run some code when a value goes out of scope. This
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/test/compile-fail/unsized3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down