@@ -1048,25 +1048,31 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10481048 err. span_label ( span, format ! ( "expected {} that takes {}" , kind, expected_str) ) ;
10491049
10501050 if let Some ( found_span) = found_span {
1051+ err. span_label ( found_span, format ! ( "takes {}" , found_str) ) ;
1052+
10511053 // Suggest to take and ignore the arguments with expected_args_length `_`s if
10521054 // found arguments is empty(Suppose the user just wants to ignore args in this case).
10531055 // like `|_, _|` for closure with 2 expected args.
10541056 if found_args. is_empty ( ) && is_closure {
10551057 let mut underscores = "_" . repeat ( expected_args. len ( ) )
1056- . split ( "" )
1057- . filter ( |s| !s. is_empty ( ) )
1058- . collect :: < Vec < _ > > ( )
1059- . join ( ", " ) ;
1060- err. span_suggestion (
1058+ . split ( "" )
1059+ . filter ( |s| !s. is_empty ( ) )
1060+ . collect :: < Vec < _ > > ( )
1061+ . join ( ", " ) ;
1062+ err. span_suggestion_with_applicability (
10611063 found_span,
1062- "consider changing this to" ,
1064+ & format ! ( "change the closure to take and ignore the argument{}" ,
1065+ if expected_args. len( ) < 2 {
1066+ ""
1067+ } else {
1068+ "s"
1069+ }
1070+ ) ,
10631071 format ! ( "|{}|" , underscores) ,
1072+ Applicability :: MachineApplicable ,
10641073 ) ;
1065- } else {
1066- err. span_label ( found_span, format ! ( "takes {}" , found_str) ) ;
10671074 }
10681075
1069-
10701076 if let & [ ArgKind :: Tuple ( _, ref fields) ] = & found_args[ ..] {
10711077 if fields. len ( ) == expected_args. len ( ) {
10721078 let sugg = fields. iter ( )
0 commit comments