about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Prouillet <vincent@wearewizards.io>2016-08-05 16:27:40 +0100
committerVincent Prouillet <vincent@wearewizards.io>2016-08-05 20:10:27 +0100
commite0035c9797bf1fa5c2f87935e4ba7d362888d299 (patch)
treeec3450b749fd5dc5c9deae5aa94b1d433751cb5a
parent271d048523b6c1b0e773d9e5cc76bbb997cc180c (diff)
downloadrust-e0035c9797bf1fa5c2f87935e4ba7d362888d299.tar.gz
rust-e0035c9797bf1fa5c2f87935e4ba7d362888d299.zip
Update error message for E0323, E0324 and E0325
-rw-r--r--src/librustc_typeck/check/mod.rs31
-rw-r--r--src/test/compile-fail/impl-wrong-item-for-trait.rs7
2 files changed, 30 insertions, 8 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 6062bd048b3..f384ae2b88e 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -993,7 +993,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
     // Check existing impl methods to see if they are both present in trait
     // and compatible with trait signature
     for impl_item in impl_items {
-        let ty_impl_item = ccx.tcx.impl_or_trait_item(ccx.tcx.map.local_def_id(impl_item.id));
+        let ty_impl_item = tcx.impl_or_trait_item(tcx.map.local_def_id(impl_item.id));
         let ty_trait_item = trait_items.iter()
             .find(|ac| ac.name() == ty_impl_item.name());
 
@@ -1014,11 +1014,18 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
                                            trait_const,
                                            &impl_trait_ref);
                     } else {
-                        span_err!(tcx.sess, impl_item.span, E0323,
+                         let mut err = struct_span_err!(tcx.sess, impl_item.span, E0323,
                                   "item `{}` is an associated const, \
                                   which doesn't match its trait `{:?}`",
                                   impl_const.name,
-                                  impl_trait_ref)
+                                  impl_trait_ref);
+                         err.span_label(impl_item.span, &format!("does not match trait"));
+                         // We can only get the spans from local trait definition
+                         // Same for E0324 and E0325
+                         if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) {
+                            err.span_label(trait_span, &format!("original trait requirement"));
+                         }
+                         err.emit()
                     }
                 }
                 hir::ImplItemKind::Method(ref sig, ref body) => {
@@ -1037,11 +1044,16 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
                                             &trait_method,
                                             &impl_trait_ref);
                     } else {
-                        span_err!(tcx.sess, impl_item.span, E0324,
+                        let mut err = struct_span_err!(tcx.sess, impl_item.span, E0324,
                                   "item `{}` is an associated method, \
                                   which doesn't match its trait `{:?}`",
                                   impl_method.name,
-                                  impl_trait_ref)
+                                  impl_trait_ref);
+                         err.span_label(impl_item.span, &format!("does not match trait"));
+                         if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) {
+                            err.span_label(trait_span, &format!("original trait requirement"));
+                         }
+                         err.emit()
                     }
                 }
                 hir::ImplItemKind::Type(_) => {
@@ -1055,11 +1067,16 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
                             overridden_associated_type = Some(impl_item);
                         }
                     } else {
-                        span_err!(tcx.sess, impl_item.span, E0325,
+                        let mut err = struct_span_err!(tcx.sess, impl_item.span, E0325,
                                   "item `{}` is an associated type, \
                                   which doesn't match its trait `{:?}`",
                                   impl_type.name,
-                                  impl_trait_ref)
+                                  impl_trait_ref);
+                         err.span_label(impl_item.span, &format!("does not match trait"));
+                         if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) {
+                            err.span_label(trait_span, &format!("original trait requirement"));
+                         }
+                         err.emit()
                     }
                 }
             }
diff --git a/src/test/compile-fail/impl-wrong-item-for-trait.rs b/src/test/compile-fail/impl-wrong-item-for-trait.rs
index 9b3e28cbc01..6452e50d089 100644
--- a/src/test/compile-fail/impl-wrong-item-for-trait.rs
+++ b/src/test/compile-fail/impl-wrong-item-for-trait.rs
@@ -12,7 +12,9 @@
 
 trait Foo {
     fn bar(&self);
-    const MY_CONST: u32;
+    //~^ NOTE original trait requirement
+    //~| NOTE original trait requirement
+    const MY_CONST: u32; //~ NOTE original trait requirement
 }
 
 pub struct FooConstForMethod;
@@ -21,6 +23,7 @@ impl Foo for FooConstForMethod {
     //~^ ERROR E0046
     const bar: u64 = 1;
     //~^ ERROR E0323
+    //~| NOTE does not match trait
     const MY_CONST: u32 = 1;
 }
 
@@ -31,6 +34,7 @@ impl Foo for FooMethodForConst {
     fn bar(&self) {}
     fn MY_CONST() {}
     //~^ ERROR E0324
+    //~| NOTE does not match trait
 }
 
 pub struct FooTypeForMethod;
@@ -39,6 +43,7 @@ impl Foo for FooTypeForMethod {
     //~^ ERROR E0046
     type bar = u64;
     //~^ ERROR E0325
+    //~| NOTE does not match trait
     const MY_CONST: u32 = 1;
 }