@@ -1339,16 +1339,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1339
1339
err. span_label (
1340
1340
* sp,
1341
1341
format ! (
1342
- "{}this is {}the {} {}{}" ,
1342
+ "{}the {} {}{}{}" ,
1343
+ if count > 1 { "one of " } else { "" } ,
1344
+ target,
1345
+ key,
1346
+ pluralize!( count) ,
1343
1347
if sp. is_desugaring( DesugaringKind :: Async ) {
1344
- "in the desugared `async fn`, "
1348
+ " in the `Output` of this `async fn`"
1345
1349
} else {
1346
1350
""
1347
1351
} ,
1348
- if count > 1 { "one of" } else { "" } ,
1349
- target,
1350
- key,
1351
- pluralize!( count) ,
1352
1352
) ,
1353
1353
) ;
1354
1354
}
@@ -1364,18 +1364,24 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1364
1364
ty:: Opaque ( ..) => "opaque type" ,
1365
1365
_ => "" ,
1366
1366
} ;
1367
- match t. kind {
1368
- ty:: Closure ( def_id, _) | ty:: Opaque ( def_id, _) => {
1369
- let span = self . tcx . def_span ( def_id) ;
1370
- debug ! ( "note_type_err visit_ty {:?}" , span. macro_backtrace( ) ) ;
1371
- if !self . ignore_span . overlaps ( span)
1372
- && !self . expected . values ( ) . any ( |exp| exp. iter ( ) . any ( |sp| * sp == span) )
1373
- {
1374
- let entry = self . types . entry ( kind) . or_default ( ) ;
1375
- entry. insert ( span) ;
1376
- }
1367
+ if let ty:: Closure ( def_id, _) | ty:: Opaque ( def_id, _) = t. kind {
1368
+ let span = self . tcx . def_span ( def_id) ;
1369
+ // Avoid cluttering the output when the "found" and error span overlap:
1370
+ //
1371
+ // error[E0308]: mismatched types
1372
+ // --> $DIR/issue-20862.rs:2:5
1373
+ // |
1374
+ // LL | |y| x + y
1375
+ // | ^^^^^^^^^
1376
+ // | |
1377
+ // | the found closure
1378
+ // | expected `()`, found closure
1379
+ // |
1380
+ // = note: expected unit type `()`
1381
+ // found closure `[closure@$DIR/issue-20862.rs:2:5: 2:14 x:_]`
1382
+ if !self . ignore_span . overlaps ( span) {
1383
+ self . types . entry ( kind) . or_default ( ) . insert ( span) ;
1377
1384
}
1378
- _ => { }
1379
1385
}
1380
1386
t. super_visit_with ( self )
1381
1387
}
0 commit comments