about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonathan Turner <jonathandturner@users.noreply.github.com>2016-08-08 13:25:59 -0700
committerGitHub <noreply@github.com>2016-08-08 13:25:59 -0700
commita72891e9e8aa789c2fa0bd101a5c69d342985a1e (patch)
tree01e389362823358111d3dc665e19b0beb719002b
parent8a7edc01166da9c1c77989384d5f5cbdd05e4b23 (diff)
parentc6e17ec2769cf8c67b71451e84cfa49a4f247103 (diff)
downloadrust-a72891e9e8aa789c2fa0bd101a5c69d342985a1e.tar.gz
rust-a72891e9e8aa789c2fa0bd101a5c69d342985a1e.zip
Rollup merge of #35484 - KiChjang:e0205-bonus, r=GuillaumeGomez
Shrink E0205 span label to the trait being implemented

Part of #35233.
Extension of #35468.
Closes #35382.

r? @GuillaumeGomez
-rw-r--r--src/librustc_typeck/coherence/mod.rs19
-rw-r--r--src/test/compile-fail/E0205.rs4
2 files changed, 14 insertions, 9 deletions
diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs
index cdf2ca14d4c..7a923cd29d0 100644
--- a/src/librustc_typeck/coherence/mod.rs
+++ b/src/librustc_typeck/coherence/mod.rs
@@ -321,13 +321,18 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
 
                 }
                 Err(CopyImplementationError::InfrigingVariant(name)) => {
-                       struct_span_err!(tcx.sess, span, E0205,
-                                 "the trait `Copy` may not be \
-                                          implemented for this type")
-                           .span_label(span, &format!("variant \
-                                          `{}` does not implement `Copy`",
-                                         name))
-                           .emit()
+                    let item = tcx.map.expect_item(impl_node_id);
+                    let span = if let ItemImpl(_, _, _, Some(ref tr), _, _) = item.node {
+                        tr.path.span
+                    } else {
+                        span
+                    };
+
+                    struct_span_err!(tcx.sess, span, E0205,
+                                     "the trait `Copy` may not be implemented for this type")
+                        .span_label(span, &format!("variant `{}` does not implement `Copy`",
+                                                   name))
+                        .emit()
                 }
                 Err(CopyImplementationError::NotAnAdt) => {
                     let item = tcx.map.expect_item(impl_node_id);
diff --git a/src/test/compile-fail/E0205.rs b/src/test/compile-fail/E0205.rs
index 37ac57af524..c73e7534301 100644
--- a/src/test/compile-fail/E0205.rs
+++ b/src/test/compile-fail/E0205.rs
@@ -14,11 +14,11 @@ enum Foo {
 }
 
 impl Copy for Foo { }
-//~^ ERROR E0205
+//~^ ERROR the trait `Copy` may not be implemented for this type
 //~| NOTE variant `Bar` does not implement `Copy`
 
 #[derive(Copy)]
-//~^ ERROR E0205
+//~^ ERROR the trait `Copy` may not be implemented for this type
 //~| NOTE variant `Bar` does not implement `Copy`
 //~| NOTE in this expansion of #[derive(Copy)]
 enum Foo2<'a> {