about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMikhail Modin <mikhailm1@gmail.com>2016-08-15 20:37:03 +0300
committerMikhail Modin <mikhailm1@gmail.com>2016-08-15 20:37:03 +0300
commit349f10a15daee7b952889f6a88ea09be76711702 (patch)
tree5cba45949dc430747474b4eba51b9f6711ed4c36
parente64f68817d850ccbe642d7f067083bc655115d84 (diff)
downloadrust-349f10a15daee7b952889f6a88ea09be76711702.tar.gz
rust-349f10a15daee7b952889f6a88ea09be76711702.zip
update E0375 to new format
-rw-r--r--src/librustc_typeck/coherence/mod.rs26
-rw-r--r--src/test/compile-fail/E0375.rs8
2 files changed, 26 insertions, 8 deletions
diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs
index 13deac57330..f33fb299cac 100644
--- a/src/librustc_typeck/coherence/mod.rs
+++ b/src/librustc_typeck/coherence/mod.rs
@@ -458,13 +458,25 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
                                        being coerced, none found");
                             return;
                         } else if diff_fields.len() > 1 {
-                            span_err!(tcx.sess, span, E0375,
-                                      "the trait `CoerceUnsized` may only be implemented \
-                                       for a coercion between structures with one field \
-                                       being coerced, but {} fields need coercions: {}",
-                                       diff_fields.len(), diff_fields.iter().map(|&(i, a, b)| {
-                                            format!("{} ({} to {})", fields[i].name, a, b)
-                                       }).collect::<Vec<_>>().join(", "));
+                            let item = tcx.map.expect_item(impl_node_id);
+                            let span = if let ItemImpl(_, _, _, Some(ref t), _, _) = item.node {
+                                t.path.span
+                            } else {
+                                tcx.map.span(impl_node_id)
+                            };
+
+                            let mut err = struct_span_err!(tcx.sess, span, E0375,
+                                      "implementing the trait `CoerceUnsized` \
+                                       requires multiple coercions");
+                            err.note("`CoerceUnsized` may only be implemented for \
+                                      a coercion between structures with one field being coerced");
+                            err.note(&format!("currently, {} fields need coercions: {}",
+                                             diff_fields.len(),
+                                             diff_fields.iter().map(|&(i, a, b)| {
+                                                format!("{} ({} to {})", fields[i].name, a, b)
+                                             }).collect::<Vec<_>>().join(", ") ));
+                            err.span_label(span, &format!("requires multiple coercions"));
+                            err.emit();
                             return;
                         }
 
diff --git a/src/test/compile-fail/E0375.rs b/src/test/compile-fail/E0375.rs
index c6db7b8b64e..29d8e920c4c 100644
--- a/src/test/compile-fail/E0375.rs
+++ b/src/test/compile-fail/E0375.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// ignore-tidy-linelength
+
 #![feature(coerce_unsized)]
 use std::ops::CoerceUnsized;
 
@@ -17,6 +19,10 @@ struct Foo<T: ?Sized, U: ?Sized> {
     c: U,
 }
 
-impl<T, U> CoerceUnsized<Foo<U, T>> for Foo<T, U> {} //~ ERROR E0375
+impl<T, U> CoerceUnsized<Foo<U, T>> for Foo<T, U> {}
+//~^ ERROR E0375
+//~| NOTE requires multiple coercions
+//~| NOTE `CoerceUnsized` may only be implemented for a coercion between structures with one field being coerced
+//~| NOTE currently, 2 fields need coercions: b (T to U), c (U to T)
 
 fn main() {}