diff options
| author | bors <bors@rust-lang.org> | 2016-08-07 17:31:55 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-07 17:31:55 -0700 |
| commit | 6153bbbe38ea1a96834b1be4dc457a698c4713b3 (patch) | |
| tree | 80d2faa04310b1741db6c41b7871082125b19028 | |
| parent | 1744c46e47434d8c0b63a839678ce45f1988bb74 (diff) | |
| parent | 53baa09bfe1bb8211060dae3eb8bbfe0c637cfb7 (diff) | |
| download | rust-6153bbbe38ea1a96834b1be4dc457a698c4713b3.tar.gz rust-6153bbbe38ea1a96834b1be4dc457a698c4713b3.zip | |
Auto merge of #35402 - KiChjang:e0206-new-msg, r=GuillaumeGomez
Update E0206 message to new format Part of #35233. Fixes #35301. r? @GuillaumeGomez
| -rw-r--r-- | src/librustc_typeck/coherence/mod.rs | 15 | ||||
| -rw-r--r-- | src/test/compile-fail/E0206.rs | 12 | ||||
| -rw-r--r-- | src/test/compile-fail/coherence-impls-copy.rs | 27 |
3 files changed, 39 insertions, 15 deletions
diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 939d81bf847..cdf2ca14d4c 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 31b01da3d75..888e42ed3a1 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 9c210c132a3..f686a146042 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() { } |
