@@ -23,6 +23,7 @@ use std::marker::PhantomData;
23
23
use std:: ops:: { ControlFlow , Deref } ;
24
24
25
25
use borrow_set:: LocalsStateAtExit ;
26
+ use diagnostics:: RegionErrors ;
26
27
use root_cx:: BorrowCheckRootCtxt ;
27
28
use rustc_abi:: FieldIdx ;
28
29
use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
@@ -362,13 +363,63 @@ fn do_mir_borrowck<'tcx>(
362
363
// information.
363
364
nll:: dump_annotation ( & infcx, body, & regioncx, & opt_closure_req) ;
364
365
366
+ let used_mut_upvars = borrowck_body (
367
+ root_cx,
368
+ & infcx,
369
+ & body,
370
+ & promoted,
371
+ & location_table,
372
+ & move_data,
373
+ & borrow_set,
374
+ & regioncx,
375
+ polonius_output. as_deref ( ) ,
376
+ polonius_diagnostics. as_ref ( ) ,
377
+ nll_errors,
378
+ ) ;
379
+
380
+ let result =
381
+ PropagatedBorrowCheckResults { closure_requirements : opt_closure_req, used_mut_upvars } ;
382
+
383
+ let body_with_facts = if consumer_options. is_some ( ) {
384
+ Some ( Box :: new ( BodyWithBorrowckFacts {
385
+ body : body_owned,
386
+ promoted,
387
+ borrow_set,
388
+ region_inference_context : regioncx,
389
+ location_table : polonius_input. as_ref ( ) . map ( |_| location_table) ,
390
+ input_facts : polonius_input,
391
+ output_facts : polonius_output,
392
+ } ) )
393
+ } else {
394
+ None
395
+ } ;
396
+
397
+ debug ! ( "do_mir_borrowck: result = {:#?}" , result) ;
398
+
399
+ ( result, body_with_facts)
400
+ }
401
+
402
+ fn borrowck_body < ' tcx > (
403
+ root_cx : & mut BorrowCheckRootCtxt < ' tcx > ,
404
+ infcx : & BorrowckInferCtxt < ' tcx > ,
405
+ body : & Body < ' tcx > ,
406
+ promoted : & IndexVec < Promoted , Body < ' tcx > > ,
407
+ location_table : & PoloniusLocationTable ,
408
+ move_data : & MoveData < ' tcx > ,
409
+ borrow_set : & BorrowSet < ' tcx > ,
410
+ regioncx : & RegionInferenceContext < ' tcx > ,
411
+ polonius_output : Option < & PoloniusOutput > ,
412
+ polonius_diagnostics : Option < & PoloniusDiagnosticsContext > ,
413
+ nll_errors : RegionErrors < ' tcx > ,
414
+ ) -> SmallVec < [ FieldIdx ; 8 ] > {
415
+ let tcx = infcx. tcx ;
365
416
let movable_coroutine = body. coroutine . is_some ( )
366
- && tcx. coroutine_movability ( def . to_def_id ( ) ) == hir:: Movability :: Movable ;
417
+ && tcx. coroutine_movability ( body . source . def_id ( ) ) == hir:: Movability :: Movable ;
367
418
368
419
let diags_buffer = & mut BorrowckDiagnosticsBuffer :: default ( ) ;
369
420
// While promoteds should mostly be correct by construction, we need to check them for
370
421
// invalid moves to detect moving out of arrays:`struct S; fn main() { &([S][0]); }`.
371
- for promoted_body in & promoted {
422
+ for promoted_body in promoted {
372
423
use rustc_middle:: mir:: visit:: Visitor ;
373
424
// This assumes that we won't use some of the fields of the `promoted_mbcx`
374
425
// when detecting and reporting move errors. While it would be nice to move
@@ -394,10 +445,11 @@ fn do_mir_borrowck<'tcx>(
394
445
local_names : IndexVec :: from_elem ( None , & promoted_body. local_decls ) ,
395
446
region_names : RefCell :: default ( ) ,
396
447
next_region_name : RefCell :: new ( 1 ) ,
397
- polonius_output : None ,
398
448
move_errors : Vec :: new ( ) ,
399
449
diags_buffer,
400
- polonius_diagnostics : polonius_diagnostics. as_ref ( ) ,
450
+
451
+ polonius_output,
452
+ polonius_diagnostics,
401
453
} ;
402
454
struct MoveVisitor < ' a , ' b , ' infcx , ' tcx > {
403
455
ctxt : & ' a mut MirBorrowckCtxt < ' b , ' infcx , ' tcx > ,
@@ -445,18 +497,18 @@ fn do_mir_borrowck<'tcx>(
445
497
access_place_error_reported : Default :: default ( ) ,
446
498
reservation_error_reported : Default :: default ( ) ,
447
499
uninitialized_error_reported : Default :: default ( ) ,
448
- regioncx : & regioncx ,
500
+ regioncx,
449
501
used_mut : Default :: default ( ) ,
450
502
used_mut_upvars : SmallVec :: new ( ) ,
451
503
borrow_set : & borrow_set,
452
- upvars : tcx. closure_captures ( def ) ,
504
+ upvars : tcx. closure_captures ( body . source . def_id ( ) . expect_local ( ) ) ,
453
505
local_names,
454
506
region_names : RefCell :: default ( ) ,
455
507
next_region_name : RefCell :: new ( 1 ) ,
456
508
move_errors : Vec :: new ( ) ,
457
509
diags_buffer,
458
- polonius_output : polonius_output . as_deref ( ) ,
459
- polonius_diagnostics : polonius_diagnostics . as_ref ( ) ,
510
+ polonius_output,
511
+ polonius_diagnostics,
460
512
} ;
461
513
462
514
// Compute and report region errors, if any.
@@ -496,28 +548,7 @@ fn do_mir_borrowck<'tcx>(
496
548
mbcx. root_cx . set_tainted_by_errors ( guar) ;
497
549
}
498
550
499
- let result = PropagatedBorrowCheckResults {
500
- closure_requirements : opt_closure_req,
501
- used_mut_upvars : mbcx. used_mut_upvars ,
502
- } ;
503
-
504
- let body_with_facts = if consumer_options. is_some ( ) {
505
- Some ( Box :: new ( BodyWithBorrowckFacts {
506
- body : body_owned,
507
- promoted,
508
- borrow_set,
509
- region_inference_context : regioncx,
510
- location_table : polonius_input. as_ref ( ) . map ( |_| location_table) ,
511
- input_facts : polonius_input,
512
- output_facts : polonius_output,
513
- } ) )
514
- } else {
515
- None
516
- } ;
517
-
518
- debug ! ( "do_mir_borrowck: result = {:#?}" , result) ;
519
-
520
- ( result, body_with_facts)
551
+ mbcx. used_mut_upvars
521
552
}
522
553
523
554
fn get_flow_results < ' a , ' tcx > (
0 commit comments