Skip to content

Commit ae59b96

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35402 - KiChjang:e0206-new-msg, r=GuillaumeGomez
Update E0206 message to new format Part of rust-lang#35233. Fixes rust-lang#35301. r? @GuillaumeGomez
2 parents 5e84fc4 + 5bab0e6 commit ae59b96

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
@@ -325,10 +325,17 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
325325
name)
326326
}
327327
Err(CopyImplementationError::NotAnAdt) => {
328-
span_err!(tcx.sess, span, E0206,
329-
"the trait `Copy` may not be implemented \
330-
for this type; type is not a structure or \
331-
enumeration")
328+
let item = tcx.map.expect_item(impl_node_id);
329+
let span = if let ItemImpl(_, _, _, _, ref ty, _) = item.node {
330+
ty.span
331+
} else {
332+
span
333+
};
334+
335+
struct_span_err!(tcx.sess, span, E0206,
336+
"the trait `Copy` may not be implemented for this type")
337+
.span_label(span, &format!("type is not a structure or enumeration"))
338+
.emit();
332339
}
333340
Err(CopyImplementationError::HasDestructor) => {
334341
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)