Skip to content

Commit b48ffa0

Browse files
committed
Use 'a different' for trait object mismatches too
1 parent 89af153 commit b48ffa0

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/librustc/middle/ty.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5311,6 +5311,16 @@ impl<'tcx> TyS<'tcx> {
53115311
impl<'tcx> fmt::Display for TypeError<'tcx> {
53125312
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
53135313
use self::TypeError::*;
5314+
fn report_maybe_different(f: &mut fmt::Formatter,
5315+
expected: String, found: String) -> fmt::Result {
5316+
// A naive approach to making sure that we're not reporting silly errors such as:
5317+
// (expected closure, found closure).
5318+
if expected == found {
5319+
write!(f, "expected {}, found a different {}", expected, found)
5320+
} else {
5321+
write!(f, "expected {}, found {}", expected, found)
5322+
}
5323+
}
53145324

53155325
match *self {
53165326
CyclicTy => write!(f, "cyclic type of infinite size"),
@@ -5371,20 +5381,15 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
53715381
found bound lifetime parameter {}", br)
53725382
}
53735383
Sorts(values) => tls::with(|tcx| {
5374-
// A naive approach to making sure that we're not reporting silly errors such as:
5375-
// (expected closure, found closure).
5376-
let expected_str = values.expected.sort_string(tcx);
5377-
let found_str = values.found.sort_string(tcx);
5378-
if expected_str == found_str {
5379-
write!(f, "expected {}, found a different {}", expected_str, found_str)
5380-
} else {
5381-
write!(f, "expected {}, found {}", expected_str, found_str)
5382-
}
5384+
report_maybe_different(f, values.expected.sort_string(tcx),
5385+
values.found.sort_string(tcx))
53835386
}),
53845387
Traits(values) => tls::with(|tcx| {
5385-
write!(f, "expected trait `{}`, found trait `{}`",
5386-
tcx.item_path_str(values.expected),
5387-
tcx.item_path_str(values.found))
5388+
report_maybe_different(f,
5389+
format!("trait `{}`",
5390+
tcx.item_path_str(values.expected)),
5391+
format!("trait `{}`",
5392+
tcx.item_path_str(values.found)))
53885393
}),
53895394
BuiltinBoundsMismatch(values) => {
53905395
if values.expected.is_empty() {

0 commit comments

Comments
 (0)