Skip to content

Commit 2df3a5b

Browse files
committed
Check concrete type in impls with no trait
closes rust-lang#16955
1 parent e024017 commit 2df3a5b

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/librustc/middle/kind.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_t
175175
fn check_item(cx: &mut Context, item: &Item) {
176176
if !attr::contains_name(item.attrs.as_slice(), "unsafe_destructor") {
177177
match item.node {
178-
ItemImpl(_, Some(ref trait_ref), ref self_type, _) => {
179-
check_impl_of_trait(cx, item, trait_ref, &**self_type);
180-
178+
ItemImpl(_, ref trait_ref, ref self_type, _) => {
181179
let parameter_environment =
182180
ParameterEnvironment::for_item(cx.tcx, item.id);
183181
cx.parameter_environments.push(parameter_environment);
@@ -188,16 +186,23 @@ fn check_item(cx: &mut Context, item: &Item) {
188186
item.span,
189187
ty::node_id_to_type(cx.tcx, item.id));
190188

191-
// Check bounds on the trait ref.
192-
match ty::impl_trait_ref(cx.tcx,
193-
ast_util::local_def(item.id)) {
194-
None => {}
195-
Some(trait_ref) => {
196-
check_bounds_on_structs_or_enums_in_trait_ref(
197-
cx,
198-
item.span,
199-
&*trait_ref);
189+
match trait_ref {
190+
&Some(ref trait_ref) => {
191+
check_impl_of_trait(cx, item, trait_ref, &**self_type);
192+
193+
// Check bounds on the trait ref.
194+
match ty::impl_trait_ref(cx.tcx,
195+
ast_util::local_def(item.id)) {
196+
None => {}
197+
Some(trait_ref) => {
198+
check_bounds_on_structs_or_enums_in_trait_ref(
199+
cx,
200+
item.span,
201+
&*trait_ref);
202+
}
203+
}
200204
}
205+
&None => {}
201206
}
202207

203208
drop(cx.parameter_environments.pop());

src/test/compile-fail/trait-bounds-on-structs-and-enums.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ fn kaboom(y: Bar<f32>) {}
2828
//~^ ERROR failed to find an implementation
2929
//~^^ ERROR instantiating a type parameter with an incompatible type
3030

31-
impl<T> Foo<T> {
31+
impl<T> Foo<T> { //~ ERROR failed to find an implementation
32+
//~^ ERROR instantiating a type parameter with an incompatible type
3233
fn uhoh() {}
3334
}
3435

src/test/compile-fail/unsized3.rs

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ trait T3<Sized? Z> {
7676
struct S4<Y>;
7777
impl<Sized? X> T3<X> for S4<X> { //~ ERROR instantiating a type parameter with an incompatible type
7878
}
79+
impl<Sized? X> S4<X> { //~ ERROR instantiating a type parameter with an incompatible type
80+
}
7981

8082

8183
pub fn main() {

0 commit comments

Comments
 (0)