@@ -12,7 +12,7 @@ use rustc_middle::mir::{
12
12
use rustc_middle:: ty:: { self , suggest_constraining_type_param, Ty } ;
13
13
use rustc_span:: source_map:: DesugaringKind ;
14
14
use rustc_span:: symbol:: sym;
15
- use rustc_span:: { MultiSpan , Span , DUMMY_SP } ;
15
+ use rustc_span:: { BytePos , MultiSpan , Span , DUMMY_SP } ;
16
16
use rustc_trait_selection:: infer:: InferCtxtExt ;
17
17
18
18
use crate :: dataflow:: drop_flag_effects;
@@ -1393,18 +1393,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1393
1393
let tcx = self . infcx . tcx ;
1394
1394
let args_span = use_span. args_or_use ( ) ;
1395
1395
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) => {
1398
1398
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 ( ) )
1400
1401
} 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 ( ) )
1402
1404
} else {
1403
- string. insert_str ( 0 , "move " ) ;
1404
- } ;
1405
- string
1405
+ ( args_span. shrink_to_lo ( ) , "move " . to_string ( ) )
1406
+ }
1406
1407
}
1407
- Err ( _) => "move |<args>| <body>" . to_string ( ) ,
1408
+ Err ( _) => ( args_span , "move |<args>| <body>" . to_string ( ) ) ,
1408
1409
} ;
1409
1410
let kind = match use_span. generator_kind ( ) {
1410
1411
Some ( generator_kind) => match generator_kind {
@@ -1420,8 +1421,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1420
1421
1421
1422
let mut err =
1422
1423
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 ,
1425
1426
& format ! (
1426
1427
"to force the {} to take ownership of {} (and any \
1427
1428
other referenced variables), use the `move` keyword",
0 commit comments