Skip to content

Commit 349f10a

Browse files
committed
update E0375 to new format
1 parent e64f688 commit 349f10a

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/librustc_typeck/coherence/mod.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,25 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
458458
being coerced, none found");
459459
return;
460460
} else if diff_fields.len() > 1 {
461-
span_err!(tcx.sess, span, E0375,
462-
"the trait `CoerceUnsized` may only be implemented \
463-
for a coercion between structures with one field \
464-
being coerced, but {} fields need coercions: {}",
465-
diff_fields.len(), diff_fields.iter().map(|&(i, a, b)| {
466-
format!("{} ({} to {})", fields[i].name, a, b)
467-
}).collect::<Vec<_>>().join(", "));
461+
let item = tcx.map.expect_item(impl_node_id);
462+
let span = if let ItemImpl(_, _, _, Some(ref t), _, _) = item.node {
463+
t.path.span
464+
} else {
465+
tcx.map.span(impl_node_id)
466+
};
467+
468+
let mut err = struct_span_err!(tcx.sess, span, E0375,
469+
"implementing the trait `CoerceUnsized` \
470+
requires multiple coercions");
471+
err.note("`CoerceUnsized` may only be implemented for \
472+
a coercion between structures with one field being coerced");
473+
err.note(&format!("currently, {} fields need coercions: {}",
474+
diff_fields.len(),
475+
diff_fields.iter().map(|&(i, a, b)| {
476+
format!("{} ({} to {})", fields[i].name, a, b)
477+
}).collect::<Vec<_>>().join(", ") ));
478+
err.span_label(span, &format!("requires multiple coercions"));
479+
err.emit();
468480
return;
469481
}
470482

src/test/compile-fail/E0375.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
12+
1113
#![feature(coerce_unsized)]
1214
use std::ops::CoerceUnsized;
1315

@@ -17,6 +19,10 @@ struct Foo<T: ?Sized, U: ?Sized> {
1719
c: U,
1820
}
1921

20-
impl<T, U> CoerceUnsized<Foo<U, T>> for Foo<T, U> {} //~ ERROR E0375
22+
impl<T, U> CoerceUnsized<Foo<U, T>> for Foo<T, U> {}
23+
//~^ ERROR E0375
24+
//~| NOTE requires multiple coercions
25+
//~| NOTE `CoerceUnsized` may only be implemented for a coercion between structures with one field being coerced
26+
//~| NOTE currently, 2 fields need coercions: b (T to U), c (U to T)
2127

2228
fn main() {}

0 commit comments

Comments
 (0)