@@ -1339,16 +1339,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13391339 err. span_label (
13401340 * sp,
13411341 format ! (
1342- "{}this is {}the {} {}{}" ,
1342+ "{}the {} {}{}{}" ,
1343+ if count > 1 { "one of " } else { "" } ,
1344+ target,
1345+ key,
1346+ pluralize!( count) ,
13431347 if sp. is_desugaring( DesugaringKind :: Async ) {
1344- "in the desugared `async fn`, "
1348+ " in the `Output` of this `async fn`"
13451349 } else {
13461350 ""
13471351 } ,
1348- if count > 1 { "one of" } else { "" } ,
1349- target,
1350- key,
1351- pluralize!( count) ,
13521352 ) ,
13531353 ) ;
13541354 }
@@ -1364,18 +1364,24 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13641364 ty:: Opaque ( ..) => "opaque type" ,
13651365 _ => "" ,
13661366 } ;
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) ;
13771384 }
1378- _ => { }
13791385 }
13801386 t. super_visit_with ( self )
13811387 }
0 commit comments