Skip to content

Commit 53baa09

Browse files
committed
Update E0206 message to new format
1 parent 1744c46 commit 53baa09

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

src/librustc_typeck/coherence/mod.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,17 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
330330
.emit()
331331
}
332332
Err(CopyImplementationError::NotAnAdt) => {
333-
span_err!(tcx.sess, span, E0206,
334-
"the trait `Copy` may not be implemented \
335-
for this type; type is not a structure or \
336-
enumeration")
333+
let item = tcx.map.expect_item(impl_node_id);
334+
let span = if let ItemImpl(_, _, _, _, ref ty, _) = item.node {
335+
ty.span
336+
} else {
337+
span
338+
};
339+
340+
struct_span_err!(tcx.sess, span, E0206,
341+
"the trait `Copy` may not be implemented for this type")
342+
.span_label(span, &format!("type is not a structure or enumeration"))
343+
.emit();
337344
}
338345
Err(CopyImplementationError::HasDestructor) => {
339346
span_err!(tcx.sess, span, E0184,

src/test/compile-fail/E0206.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010

1111
type Foo = i32;
1212

13-
impl Copy for Foo { } //~ ERROR E0206
14-
//~^ ERROR E0117
13+
impl Copy for Foo { }
14+
//~^ ERROR the trait `Copy` may not be implemented for this type
15+
//~| NOTE type is not a structure or enumeration
16+
//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
17+
//~| NOTE impl doesn't use types inside crate
18+
//~| NOTE the impl does not reference any types defined in this crate
1519

1620
#[derive(Copy, Clone)]
1721
struct Bar;
1822

19-
impl Copy for &'static Bar { } //~ ERROR E0206
23+
impl Copy for &'static Bar { }
24+
//~^ ERROR the trait `Copy` may not be implemented for this type
25+
//~| NOTE type is not a structure or enumeration
2026

2127
fn main() {
2228
}

src/test/compile-fail/coherence-impls-copy.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,34 @@ impl Clone for TestE { fn clone(&self) -> Self { *self } }
2727
impl Copy for MyType {}
2828

2929
impl Copy for &'static mut MyType {}
30-
//~^ ERROR E0206
30+
//~^ ERROR the trait `Copy` may not be implemented for this type
31+
//~| NOTE type is not a structure or enumeration
3132
impl Clone for MyType { fn clone(&self) -> Self { *self } }
3233

3334
impl Copy for (MyType, MyType) {}
34-
//~^ ERROR E0206
35-
//~| ERROR E0117
35+
//~^ ERROR the trait `Copy` may not be implemented for this type
36+
//~| NOTE type is not a structure or enumeration
37+
//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
38+
//~| NOTE impl doesn't use types inside crate
39+
//~| NOTE the impl does not reference any types defined in this crate
3640

3741
impl Copy for &'static NotSync {}
38-
//~^ ERROR E0206
42+
//~^ ERROR the trait `Copy` may not be implemented for this type
43+
//~| NOTE type is not a structure or enumeration
3944

4045
impl Copy for [MyType] {}
41-
//~^ ERROR E0206
42-
//~| ERROR E0117
46+
//~^ ERROR the trait `Copy` may not be implemented for this type
47+
//~| NOTE type is not a structure or enumeration
48+
//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
49+
//~| NOTE impl doesn't use types inside crate
50+
//~| NOTE the impl does not reference any types defined in this crate
4351

4452
impl Copy for &'static [NotSync] {}
45-
//~^ ERROR E0206
46-
//~| ERROR E0117
53+
//~^ ERROR the trait `Copy` may not be implemented for this type
54+
//~| NOTE type is not a structure or enumeration
55+
//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
56+
//~| NOTE impl doesn't use types inside crate
57+
//~| NOTE the impl does not reference any types defined in this crate
4758

4859
fn main() {
4960
}

0 commit comments

Comments
 (0)