Skip to content

Commit 5bab0e6

Browse files
committed
Update E0206 message to new format
1 parent 4c02363 commit 5bab0e6

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

src/librustc_typeck/coherence/mod.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,17 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
316316
name)
317317
}
318318
Err(CopyImplementationError::NotAnAdt) => {
319-
span_err!(tcx.sess, span, E0206,
320-
"the trait `Copy` may not be implemented \
321-
for this type; type is not a structure or \
322-
enumeration")
319+
let item = tcx.map.expect_item(impl_node_id);
320+
let span = if let ItemImpl(_, _, _, _, ref ty, _) = item.node {
321+
ty.span
322+
} else {
323+
span
324+
};
325+
326+
struct_span_err!(tcx.sess, span, E0206,
327+
"the trait `Copy` may not be implemented for this type")
328+
.span_label(span, &format!("type is not a structure or enumeration"))
329+
.emit();
323330
}
324331
Err(CopyImplementationError::HasDestructor) => {
325332
span_err!(tcx.sess, span, E0184,

src/test/compile-fail/E0206.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
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 E0117
1517

1618
#[derive(Copy, Clone)]
1719
struct Bar;
1820

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

2125
fn main() {
2226
}

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,27 @@ 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 the trait `Copy` may not be implemented for this type
36+
//~| NOTE type is not a structure or enumeration
3537
//~| ERROR E0117
3638

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

4043
impl Copy for [MyType] {}
41-
//~^ ERROR E0206
44+
//~^ ERROR the trait `Copy` may not be implemented for this type
45+
//~| NOTE type is not a structure or enumeration
4246
//~| ERROR E0117
4347

4448
impl Copy for &'static [NotSync] {}
45-
//~^ ERROR E0206
49+
//~^ ERROR the trait `Copy` may not be implemented for this type
50+
//~| NOTE type is not a structure or enumeration
4651
//~| ERROR E0117
4752

4853
fn main() {

0 commit comments

Comments
 (0)