@@ -265,7 +265,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
265
265
}
266
266
let hir = self . tcx . hir ( ) ;
267
267
// Get the name of the callable and the arguments to be used in the suggestion.
268
- let snippet = match hir. get_if_local ( def_id) {
268
+ let ( snippet, sugg ) = match hir. get_if_local ( def_id) {
269
269
Some ( hir:: Node :: Expr ( hir:: Expr {
270
270
kind : hir:: ExprKind :: Closure ( _, decl, _, span, ..) ,
271
271
..
@@ -276,7 +276,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
276
276
None => return ,
277
277
} ;
278
278
let args = decl. inputs . iter ( ) . map ( |_| "_" ) . collect :: < Vec < _ > > ( ) . join ( ", " ) ;
279
- format ! ( "{}({})" , name, args)
279
+ let sugg = format ! ( "({})" , args) ;
280
+ ( format ! ( "{}{}" , name, sugg) , sugg)
280
281
}
281
282
Some ( hir:: Node :: Item ( hir:: Item {
282
283
ident,
@@ -297,7 +298,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
297
298
} )
298
299
. collect :: < Vec < _ > > ( )
299
300
. join ( ", " ) ;
300
- format ! ( "{}({})" , ident, args)
301
+ let sugg = format ! ( "({})" , args) ;
302
+ ( format ! ( "{}{}" , ident, sugg) , sugg)
301
303
}
302
304
_ => return ,
303
305
} ;
@@ -306,10 +308,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
306
308
// an argument, the `obligation.cause.span` points at the expression
307
309
// of the argument, so we can provide a suggestion. This is signaled
308
310
// by `points_at_arg`. Otherwise, we give a more general note.
309
- err. span_suggestion (
310
- obligation. cause . span ,
311
+ err. span_suggestion_verbose (
312
+ obligation. cause . span . shrink_to_hi ( ) ,
311
313
& msg,
312
- snippet ,
314
+ sugg ,
313
315
Applicability :: HasPlaceholders ,
314
316
) ;
315
317
} else {
@@ -494,7 +496,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
494
496
. source_map ( )
495
497
. span_take_while ( span, |c| c. is_whitespace ( ) || * c == '&' ) ;
496
498
if points_at_arg && mutability == hir:: Mutability :: Not && refs_number > 0 {
497
- err. span_suggestion (
499
+ err. span_suggestion_verbose (
498
500
sp,
499
501
"consider changing this borrow's mutability" ,
500
502
"&mut " . to_string ( ) ,
@@ -898,11 +900,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
898
900
// For example, if `expected_args_length` is 2, suggest `|_, _|`.
899
901
if found_args. is_empty ( ) && is_closure {
900
902
let underscores = vec ! [ "_" ; expected_args. len( ) ] . join ( ", " ) ;
901
- err. span_suggestion (
903
+ err. span_suggestion_verbose (
902
904
pipe_span,
903
905
& format ! (
904
906
"consider changing the closure to take and ignore the expected argument{}" ,
905
- if expected_args. len( ) < 2 { "" } else { "s" }
907
+ pluralize! ( expected_args. len( ) )
906
908
) ,
907
909
format ! ( "|{}|" , underscores) ,
908
910
Applicability :: MachineApplicable ,
@@ -916,7 +918,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
916
918
. map ( |( name, _) | name. to_owned ( ) )
917
919
. collect :: < Vec < String > > ( )
918
920
. join ( ", " ) ;
919
- err. span_suggestion (
921
+ err. span_suggestion_verbose (
920
922
found_span,
921
923
"change the closure to take multiple arguments instead of a single tuple" ,
922
924
format ! ( "|{}|" , sugg) ,
@@ -953,7 +955,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
953
955
String :: new( )
954
956
} ,
955
957
) ;
956
- err. span_suggestion (
958
+ err. span_suggestion_verbose (
957
959
found_span,
958
960
"change the closure to accept a tuple instead of individual arguments" ,
959
961
sugg,
0 commit comments