Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update E0375 to new format #35686

Merged
merged 1 commit into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/librustc_typeck/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 7 additions & 1 deletion src/test/compile-fail/E0375.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() {}