diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 939d81bf8477b..cdf2ca14d4c78 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -330,10 +330,17 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> { .emit() } Err(CopyImplementationError::NotAnAdt) => { - span_err!(tcx.sess, span, E0206, - "the trait `Copy` may not be implemented \ - for this type; type is not a structure or \ - enumeration") + let item = tcx.map.expect_item(impl_node_id); + let span = if let ItemImpl(_, _, _, _, ref ty, _) = item.node { + ty.span + } else { + span + }; + + struct_span_err!(tcx.sess, span, E0206, + "the trait `Copy` may not be implemented for this type") + .span_label(span, &format!("type is not a structure or enumeration")) + .emit(); } Err(CopyImplementationError::HasDestructor) => { span_err!(tcx.sess, span, E0184, diff --git a/src/test/compile-fail/E0206.rs b/src/test/compile-fail/E0206.rs index 31b01da3d75b5..888e42ed3a18c 100644 --- a/src/test/compile-fail/E0206.rs +++ b/src/test/compile-fail/E0206.rs @@ -10,13 +10,19 @@ type Foo = i32; -impl Copy for Foo { } //~ ERROR E0206 - //~^ ERROR E0117 +impl Copy for Foo { } +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration +//~| ERROR only traits defined in the current crate can be implemented for arbitrary types +//~| NOTE impl doesn't use types inside crate +//~| NOTE the impl does not reference any types defined in this crate #[derive(Copy, Clone)] struct Bar; -impl Copy for &'static Bar { } //~ ERROR E0206 +impl Copy for &'static Bar { } +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration fn main() { } diff --git a/src/test/compile-fail/coherence-impls-copy.rs b/src/test/compile-fail/coherence-impls-copy.rs index 9c210c132a313..f686a146042ce 100644 --- a/src/test/compile-fail/coherence-impls-copy.rs +++ b/src/test/compile-fail/coherence-impls-copy.rs @@ -27,23 +27,34 @@ impl Clone for TestE { fn clone(&self) -> Self { *self } } impl Copy for MyType {} impl Copy for &'static mut MyType {} -//~^ ERROR E0206 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration impl Clone for MyType { fn clone(&self) -> Self { *self } } impl Copy for (MyType, MyType) {} -//~^ ERROR E0206 -//~| ERROR E0117 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration +//~| ERROR only traits defined in the current crate can be implemented for arbitrary types +//~| NOTE impl doesn't use types inside crate +//~| NOTE the impl does not reference any types defined in this crate impl Copy for &'static NotSync {} -//~^ ERROR E0206 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration impl Copy for [MyType] {} -//~^ ERROR E0206 -//~| ERROR E0117 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration +//~| ERROR only traits defined in the current crate can be implemented for arbitrary types +//~| NOTE impl doesn't use types inside crate +//~| NOTE the impl does not reference any types defined in this crate impl Copy for &'static [NotSync] {} -//~^ ERROR E0206 -//~| ERROR E0117 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration +//~| ERROR only traits defined in the current crate can be implemented for arbitrary types +//~| NOTE impl doesn't use types inside crate +//~| NOTE the impl does not reference any types defined in this crate fn main() { }