@@ -1048,25 +1048,31 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1048
1048
err. span_label ( span, format ! ( "expected {} that takes {}" , kind, expected_str) ) ;
1049
1049
1050
1050
if let Some ( found_span) = found_span {
1051
+ err. span_label ( found_span, format ! ( "takes {}" , found_str) ) ;
1052
+
1051
1053
// Suggest to take and ignore the arguments with expected_args_length `_`s if
1052
1054
// found arguments is empty(Suppose the user just wants to ignore args in this case).
1053
1055
// like `|_, _|` for closure with 2 expected args.
1054
1056
if found_args. is_empty ( ) && is_closure {
1055
1057
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 (
1061
1063
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
+ ) ,
1063
1071
format ! ( "|{}|" , underscores) ,
1072
+ Applicability :: MachineApplicable ,
1064
1073
) ;
1065
- } else {
1066
- err. span_label ( found_span, format ! ( "takes {}" , found_str) ) ;
1067
1074
}
1068
1075
1069
-
1070
1076
if let & [ ArgKind :: Tuple ( _, ref fields) ] = & found_args[ ..] {
1071
1077
if fields. len ( ) == expected_args. len ( ) {
1072
1078
let sugg = fields. iter ( )
0 commit comments