Skip to content

Commit c6e17ec

Browse files
committed
Shrink E0205 span label to the trait being implemented
1 parent 1744c46 commit c6e17ec

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/librustc_typeck/coherence/mod.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,18 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
321321

322322
}
323323
Err(CopyImplementationError::InfrigingVariant(name)) => {
324-
struct_span_err!(tcx.sess, span, E0205,
325-
"the trait `Copy` may not be \
326-
implemented for this type")
327-
.span_label(span, &format!("variant \
328-
`{}` does not implement `Copy`",
329-
name))
330-
.emit()
324+
let item = tcx.map.expect_item(impl_node_id);
325+
let span = if let ItemImpl(_, _, _, Some(ref tr), _, _) = item.node {
326+
tr.path.span
327+
} else {
328+
span
329+
};
330+
331+
struct_span_err!(tcx.sess, span, E0205,
332+
"the trait `Copy` may not be implemented for this type")
333+
.span_label(span, &format!("variant `{}` does not implement `Copy`",
334+
name))
335+
.emit()
331336
}
332337
Err(CopyImplementationError::NotAnAdt) => {
333338
span_err!(tcx.sess, span, E0206,

src/test/compile-fail/E0205.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ enum Foo {
1414
}
1515

1616
impl Copy for Foo { }
17-
//~^ ERROR E0205
17+
//~^ ERROR the trait `Copy` may not be implemented for this type
1818
//~| NOTE variant `Bar` does not implement `Copy`
1919

2020
#[derive(Copy)]
21-
//~^ ERROR E0205
21+
//~^ ERROR the trait `Copy` may not be implemented for this type
2222
//~| NOTE variant `Bar` does not implement `Copy`
2323
//~| NOTE in this expansion of #[derive(Copy)]
2424
enum Foo2<'a> {

0 commit comments

Comments
 (0)