1
- use crate :: diagnostics:: mutability_errors:: mut_borrow_of_mutable_ref;
2
1
use either:: Either ;
3
- use hir:: Closure ;
4
2
use rustc_const_eval:: util:: CallKind ;
5
3
use rustc_data_structures:: captures:: Captures ;
6
4
use rustc_data_structures:: fx:: FxHashSet ;
7
5
use rustc_errors:: {
8
6
struct_span_err, Applicability , Diagnostic , DiagnosticBuilder , ErrorGuaranteed , MultiSpan ,
9
7
} ;
10
8
use rustc_hir as hir;
9
+ use rustc_hir:: def:: Res ;
11
10
use rustc_hir:: intravisit:: { walk_block, walk_expr, Visitor } ;
12
11
use rustc_hir:: { AsyncGeneratorKind , GeneratorKind , LangItem } ;
13
12
use rustc_infer:: infer:: TyCtxtInferExt ;
@@ -31,6 +30,7 @@ use crate::borrowck_errors;
31
30
32
31
use crate :: diagnostics:: conflict_errors:: StorageDeadOrDrop :: LocalStorageDead ;
33
32
use crate :: diagnostics:: find_all_local_uses;
33
+ use crate :: diagnostics:: mutability_errors:: mut_borrow_of_mutable_ref;
34
34
use crate :: {
35
35
borrow_set:: BorrowData , diagnostics:: Instance , prefixes:: IsPrefixOf ,
36
36
InitializationRequiringAction , MirBorrowckCtxt , PrefixSet , WriteKind ,
@@ -41,8 +41,6 @@ use super::{
41
41
DescribePlaceOpt , RegionName , RegionNameSource , UseSpans ,
42
42
} ;
43
43
44
- use rustc_hir:: def:: Res ;
45
-
46
44
#[ derive( Debug ) ]
47
45
struct MoveSite {
48
46
/// Index of the "move out" that we found. The `MoveData` can
@@ -1280,7 +1278,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1280
1278
impl < ' hir > Visitor < ' hir > for ExpressionFinder < ' hir > {
1281
1279
fn visit_expr ( & mut self , e : & ' hir hir:: Expr < ' hir > ) {
1282
1280
if e. span . contains ( self . capture_span ) {
1283
- if let hir:: ExprKind :: Closure ( & Closure {
1281
+ if let hir:: ExprKind :: Closure ( & hir :: Closure {
1284
1282
movability : None ,
1285
1283
body,
1286
1284
fn_arg_span,
@@ -1311,7 +1309,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1311
1309
if let hir:: Pat { kind : hir:: PatKind :: Binding ( _, hir_id, _ident, _) , .. } = local. pat &&
1312
1310
let Some ( init) = local. init
1313
1311
{
1314
- if let hir:: Expr { kind : hir:: ExprKind :: Closure ( & Closure {
1312
+ if let hir:: Expr { kind : hir:: ExprKind :: Closure ( & hir :: Closure {
1315
1313
movability : None ,
1316
1314
..
1317
1315
} ) , .. } = init &&
@@ -1328,11 +1326,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1328
1326
let hir:: QPath :: Resolved ( _, hir:: Path { segments : [ seg] , ..} ) = path &&
1329
1327
let Res :: Local ( hir_id) = seg. res &&
1330
1328
Some ( hir_id) == self . closure_local_id {
1331
- let mut arg_str = "self" . to_string ( ) ;
1332
- if args. len ( ) > 0 {
1333
- arg_str. push_str ( ", " ) ;
1334
- }
1335
- self . closure_call_changes . push ( ( seg. ident . span , arg_str) ) ;
1329
+ let ( span, arg_str) = if args. len ( ) > 0 {
1330
+ ( args[ 0 ] . span . shrink_to_lo ( ) , "self, " . to_string ( ) )
1331
+ } else {
1332
+ let span = e. span . trim_start ( seg. ident . span ) . unwrap_or ( e. span ) ;
1333
+ ( span, "(self)" . to_string ( ) )
1334
+ } ;
1335
+ self . closure_call_changes . push ( ( span, arg_str) ) ;
1336
1336
}
1337
1337
hir:: intravisit:: walk_stmt ( self , s) ;
1338
1338
}
@@ -1369,9 +1369,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1369
1369
}
1370
1370
1371
1371
for ( span, suggest) in finder. closure_call_changes {
1372
- if let Ok ( span) = sm. span_extend_while ( span, |c| c != '(' ) {
1373
- sugg. push ( ( sm. next_point ( span) . shrink_to_hi ( ) , suggest) ) ;
1374
- }
1372
+ sugg. push ( ( span, suggest) ) ;
1375
1373
}
1376
1374
1377
1375
err. multipart_suggestion_verbose (
0 commit comments