@@ -265,7 +265,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
265265 }
266266 let hir = self . tcx . hir ( ) ;
267267 // 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) {
269269 Some ( hir:: Node :: Expr ( hir:: Expr {
270270 kind : hir:: ExprKind :: Closure ( _, decl, _, span, ..) ,
271271 ..
@@ -276,7 +276,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
276276 None => return ,
277277 } ;
278278 let args = decl. inputs . iter ( ) . map ( |_| "_" ) . collect :: < Vec < _ > > ( ) . join ( ", " ) ;
279- format ! ( "{}({})" , name, args)
279+ let sugg = format ! ( "({})" , args) ;
280+ ( format ! ( "{}{}" , name, sugg) , sugg)
280281 }
281282 Some ( hir:: Node :: Item ( hir:: Item {
282283 ident,
@@ -297,7 +298,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
297298 } )
298299 . collect :: < Vec < _ > > ( )
299300 . join ( ", " ) ;
300- format ! ( "{}({})" , ident, args)
301+ let sugg = format ! ( "({})" , args) ;
302+ ( format ! ( "{}{}" , ident, sugg) , sugg)
301303 }
302304 _ => return ,
303305 } ;
@@ -306,10 +308,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
306308 // an argument, the `obligation.cause.span` points at the expression
307309 // of the argument, so we can provide a suggestion. This is signaled
308310 // 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 ( ) ,
311313 & msg,
312- snippet ,
314+ sugg ,
313315 Applicability :: HasPlaceholders ,
314316 ) ;
315317 } else {
@@ -494,7 +496,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
494496 . source_map ( )
495497 . span_take_while ( span, |c| c. is_whitespace ( ) || * c == '&' ) ;
496498 if points_at_arg && mutability == hir:: Mutability :: Not && refs_number > 0 {
497- err. span_suggestion (
499+ err. span_suggestion_verbose (
498500 sp,
499501 "consider changing this borrow's mutability" ,
500502 "&mut " . to_string ( ) ,
@@ -898,11 +900,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
898900 // For example, if `expected_args_length` is 2, suggest `|_, _|`.
899901 if found_args. is_empty ( ) && is_closure {
900902 let underscores = vec ! [ "_" ; expected_args. len( ) ] . join ( ", " ) ;
901- err. span_suggestion (
903+ err. span_suggestion_verbose (
902904 pipe_span,
903905 & format ! (
904906 "consider changing the closure to take and ignore the expected argument{}" ,
905- if expected_args. len( ) < 2 { "" } else { "s" }
907+ pluralize! ( expected_args. len( ) )
906908 ) ,
907909 format ! ( "|{}|" , underscores) ,
908910 Applicability :: MachineApplicable ,
@@ -916,7 +918,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
916918 . map ( |( name, _) | name. to_owned ( ) )
917919 . collect :: < Vec < String > > ( )
918920 . join ( ", " ) ;
919- err. span_suggestion (
921+ err. span_suggestion_verbose (
920922 found_span,
921923 "change the closure to take multiple arguments instead of a single tuple" ,
922924 format ! ( "|{}|" , sugg) ,
@@ -953,7 +955,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
953955 String :: new( )
954956 } ,
955957 ) ;
956- err. span_suggestion (
958+ err. span_suggestion_verbose (
957959 found_span,
958960 "change the closure to accept a tuple instead of individual arguments" ,
959961 sugg,
0 commit comments