Skip to content

Commit

Permalink
Use 'a different' for trait object mismatches too
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Sep 8, 2015
1 parent 89af153 commit b48ffa0
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/librustc/middle/ty.rs
Expand Up @@ -5311,6 +5311,16 @@ impl<'tcx> TyS<'tcx> {
impl<'tcx> fmt::Display for TypeError<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::TypeError::*;
fn report_maybe_different(f: &mut fmt::Formatter,
expected: String, found: String) -> fmt::Result {
// A naive approach to making sure that we're not reporting silly errors such as:
// (expected closure, found closure).
if expected == found {
write!(f, "expected {}, found a different {}", expected, found)
} else {
write!(f, "expected {}, found {}", expected, found)
}
}

match *self {
CyclicTy => write!(f, "cyclic type of infinite size"),
Expand Down Expand Up @@ -5371,20 +5381,15 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
found bound lifetime parameter {}", br)
}
Sorts(values) => tls::with(|tcx| {
// A naive approach to making sure that we're not reporting silly errors such as:
// (expected closure, found closure).
let expected_str = values.expected.sort_string(tcx);
let found_str = values.found.sort_string(tcx);
if expected_str == found_str {
write!(f, "expected {}, found a different {}", expected_str, found_str)
} else {
write!(f, "expected {}, found {}", expected_str, found_str)
}
report_maybe_different(f, values.expected.sort_string(tcx),
values.found.sort_string(tcx))
}),
Traits(values) => tls::with(|tcx| {
write!(f, "expected trait `{}`, found trait `{}`",
tcx.item_path_str(values.expected),
tcx.item_path_str(values.found))
report_maybe_different(f,
format!("trait `{}`",
tcx.item_path_str(values.expected)),
format!("trait `{}`",
tcx.item_path_str(values.found)))
}),
BuiltinBoundsMismatch(values) => {
if values.expected.is_empty() {
Expand Down

0 comments on commit b48ffa0

Please sign in to comment.