@@ -12,7 +12,7 @@ use rustc_middle::mir::{
1212use rustc_middle:: ty:: { self , suggest_constraining_type_param, Ty } ;
1313use rustc_span:: source_map:: DesugaringKind ;
1414use rustc_span:: symbol:: sym;
15- use rustc_span:: { MultiSpan , Span , DUMMY_SP } ;
15+ use rustc_span:: { BytePos , MultiSpan , Span , DUMMY_SP } ;
1616use rustc_trait_selection:: infer:: InferCtxtExt ;
1717
1818use crate :: dataflow:: drop_flag_effects;
@@ -1393,18 +1393,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13931393 let tcx = self . infcx . tcx ;
13941394 let args_span = use_span. args_or_use ( ) ;
13951395
1396- let suggestion = match tcx. sess . source_map ( ) . span_to_snippet ( args_span) {
1397- Ok ( mut string) => {
1396+ let ( sugg_span , suggestion) = match tcx. sess . source_map ( ) . span_to_snippet ( args_span) {
1397+ Ok ( string) => {
13981398 if string. starts_with ( "async " ) {
1399- string. insert_str ( 6 , "move " ) ;
1399+ let pos = args_span. lo ( ) + BytePos ( 6 ) ;
1400+ ( args_span. with_lo ( pos) . with_hi ( pos) , "move " . to_string ( ) )
14001401 } else if string. starts_with ( "async|" ) {
1401- string. insert_str ( 5 , " move" ) ;
1402+ let pos = args_span. lo ( ) + BytePos ( 5 ) ;
1403+ ( args_span. with_lo ( pos) . with_hi ( pos) , " move" . to_string ( ) )
14021404 } else {
1403- string. insert_str ( 0 , "move " ) ;
1404- } ;
1405- string
1405+ ( args_span. shrink_to_lo ( ) , "move " . to_string ( ) )
1406+ }
14061407 }
1407- Err ( _) => "move |<args>| <body>" . to_string ( ) ,
1408+ Err ( _) => ( args_span , "move |<args>| <body>" . to_string ( ) ) ,
14081409 } ;
14091410 let kind = match use_span. generator_kind ( ) {
14101411 Some ( generator_kind) => match generator_kind {
@@ -1420,8 +1421,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14201421
14211422 let mut err =
14221423 self . cannot_capture_in_long_lived_closure ( args_span, kind, captured_var, var_span) ;
1423- err. span_suggestion (
1424- args_span ,
1424+ err. span_suggestion_verbose (
1425+ sugg_span ,
14251426 & format ! (
14261427 "to force the {} to take ownership of {} (and any \
14271428 other referenced variables), use the `move` keyword",
0 commit comments