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;
}
// 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;
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() {}