Skip to content

Commit

Permalink
Check concrete type in impls with no trait
Browse files Browse the repository at this point in the history
closes #16955
  • Loading branch information
nrc committed Sep 5, 2014
1 parent e024017 commit 2df3a5b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
29 changes: 17 additions & 12 deletions src/librustc/middle/kind.rs
Expand Up @@ -175,9 +175,7 @@ fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_t
fn check_item(cx: &mut Context, item: &Item) {
if !attr::contains_name(item.attrs.as_slice(), "unsafe_destructor") {
match item.node {
ItemImpl(_, Some(ref trait_ref), ref self_type, _) => {
check_impl_of_trait(cx, item, trait_ref, &**self_type);

ItemImpl(_, ref trait_ref, ref self_type, _) => {
let parameter_environment =
ParameterEnvironment::for_item(cx.tcx, item.id);
cx.parameter_environments.push(parameter_environment);
Expand All @@ -188,16 +186,23 @@ fn check_item(cx: &mut Context, item: &Item) {
item.span,
ty::node_id_to_type(cx.tcx, item.id));

// Check bounds on the trait ref.
match ty::impl_trait_ref(cx.tcx,
ast_util::local_def(item.id)) {
None => {}
Some(trait_ref) => {
check_bounds_on_structs_or_enums_in_trait_ref(
cx,
item.span,
&*trait_ref);
match trait_ref {
&Some(ref trait_ref) => {
check_impl_of_trait(cx, item, trait_ref, &**self_type);

// Check bounds on the trait ref.
match ty::impl_trait_ref(cx.tcx,
ast_util::local_def(item.id)) {
None => {}
Some(trait_ref) => {
check_bounds_on_structs_or_enums_in_trait_ref(
cx,
item.span,
&*trait_ref);
}
}
}
&None => {}
}

drop(cx.parameter_environments.pop());
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/trait-bounds-on-structs-and-enums.rs
Expand Up @@ -28,7 +28,8 @@ fn kaboom(y: Bar<f32>) {}
//~^ ERROR failed to find an implementation
//~^^ ERROR instantiating a type parameter with an incompatible type

impl<T> Foo<T> {
impl<T> Foo<T> { //~ ERROR failed to find an implementation
//~^ ERROR instantiating a type parameter with an incompatible type
fn uhoh() {}
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/unsized3.rs
Expand Up @@ -76,6 +76,8 @@ trait T3<Sized? Z> {
struct S4<Y>;
impl<Sized? X> T3<X> for S4<X> { //~ ERROR instantiating a type parameter with an incompatible type
}
impl<Sized? X> S4<X> { //~ ERROR instantiating a type parameter with an incompatible type
}


pub fn main() {
Expand Down

13 comments on commit 2df3a5b

@bors
Copy link
Contributor

@bors bors commented on 2df3a5b Sep 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at nrc@2df3a5b

@bors
Copy link
Contributor

@bors bors commented on 2df3a5b Sep 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nick29581/rust/impl = 2df3a5b into auto

@bors
Copy link
Contributor

@bors bors commented on 2df3a5b Sep 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nick29581/rust/impl = 2df3a5b merged ok, testing candidate = ac307d4a

@bors
Copy link
Contributor

@bors bors commented on 2df3a5b Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at nrc@2df3a5b

@bors
Copy link
Contributor

@bors bors commented on 2df3a5b Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nick29581/rust/impl = 2df3a5b into auto

@bors
Copy link
Contributor

@bors bors commented on 2df3a5b Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nick29581/rust/impl = 2df3a5b merged ok, testing candidate = 137325ad

@bors
Copy link
Contributor

@bors bors commented on 2df3a5b Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at nrc@2df3a5b

@bors
Copy link
Contributor

@bors bors commented on 2df3a5b Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nick29581/rust/impl = 2df3a5b into auto

@bors
Copy link
Contributor

@bors bors commented on 2df3a5b Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nick29581/rust/impl = 2df3a5b merged ok, testing candidate = 6eabd85

@bors
Copy link
Contributor

@bors bors commented on 2df3a5b Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 6eabd85

Please sign in to comment.