diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-09-08 23:50:48 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-09-08 23:50:48 +0530 |
| commit | b48ffa073fe81706a0416c6aaf70bf96d380465e (patch) | |
| tree | 72b9643f74f3c561790d165b087420bdcbb6624b | |
| parent | 89af15322dbca73b098e55bbd283a2d8a254571b (diff) | |
Use 'a different' for trait object mismatches too
| -rw-r--r-- | src/librustc/middle/ty.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 9f2c87b1a0a..99d8c5c9301 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -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"), @@ -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() { |
