@@ -5311,6 +5311,16 @@ impl<'tcx> TyS<'tcx> {
5311
5311
impl < ' tcx > fmt:: Display for TypeError < ' tcx > {
5312
5312
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5313
5313
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
+ }
5314
5324
5315
5325
match * self {
5316
5326
CyclicTy => write ! ( f, "cyclic type of infinite size" ) ,
@@ -5371,20 +5381,15 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
5371
5381
found bound lifetime parameter {}", br)
5372
5382
}
5373
5383
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) )
5383
5386
} ) ,
5384
5387
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) ) )
5388
5393
} ) ,
5389
5394
BuiltinBoundsMismatch ( values) => {
5390
5395
if values. expected . is_empty ( ) {
0 commit comments