@@ -23,6 +23,7 @@ use std::marker::PhantomData;
2323use std:: ops:: { ControlFlow , Deref } ;
2424
2525use borrow_set:: LocalsStateAtExit ;
26+ use diagnostics:: RegionErrors ;
2627use root_cx:: BorrowCheckRootCtxt ;
2728use rustc_abi:: FieldIdx ;
2829use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
@@ -362,13 +363,63 @@ fn do_mir_borrowck<'tcx>(
362363 // information.
363364 nll:: dump_annotation ( & infcx, body, & regioncx, & opt_closure_req) ;
364365
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 ;
365416 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 ;
367418
368419 let diags_buffer = & mut BorrowckDiagnosticsBuffer :: default ( ) ;
369420 // While promoteds should mostly be correct by construction, we need to check them for
370421 // 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 {
372423 use rustc_middle:: mir:: visit:: Visitor ;
373424 // This assumes that we won't use some of the fields of the `promoted_mbcx`
374425 // when detecting and reporting move errors. While it would be nice to move
@@ -394,10 +445,11 @@ fn do_mir_borrowck<'tcx>(
394445 local_names : IndexVec :: from_elem ( None , & promoted_body. local_decls ) ,
395446 region_names : RefCell :: default ( ) ,
396447 next_region_name : RefCell :: new ( 1 ) ,
397- polonius_output : None ,
398448 move_errors : Vec :: new ( ) ,
399449 diags_buffer,
400- polonius_diagnostics : polonius_diagnostics. as_ref ( ) ,
450+
451+ polonius_output,
452+ polonius_diagnostics,
401453 } ;
402454 struct MoveVisitor < ' a , ' b , ' infcx , ' tcx > {
403455 ctxt : & ' a mut MirBorrowckCtxt < ' b , ' infcx , ' tcx > ,
@@ -445,18 +497,18 @@ fn do_mir_borrowck<'tcx>(
445497 access_place_error_reported : Default :: default ( ) ,
446498 reservation_error_reported : Default :: default ( ) ,
447499 uninitialized_error_reported : Default :: default ( ) ,
448- regioncx : & regioncx ,
500+ regioncx,
449501 used_mut : Default :: default ( ) ,
450502 used_mut_upvars : SmallVec :: new ( ) ,
451503 borrow_set : & borrow_set,
452- upvars : tcx. closure_captures ( def ) ,
504+ upvars : tcx. closure_captures ( body . source . def_id ( ) . expect_local ( ) ) ,
453505 local_names,
454506 region_names : RefCell :: default ( ) ,
455507 next_region_name : RefCell :: new ( 1 ) ,
456508 move_errors : Vec :: new ( ) ,
457509 diags_buffer,
458- polonius_output : polonius_output . as_deref ( ) ,
459- polonius_diagnostics : polonius_diagnostics . as_ref ( ) ,
510+ polonius_output,
511+ polonius_diagnostics,
460512 } ;
461513
462514 // Compute and report region errors, if any.
@@ -496,28 +548,7 @@ fn do_mir_borrowck<'tcx>(
496548 mbcx. root_cx . set_tainted_by_errors ( guar) ;
497549 }
498550
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
521552}
522553
523554fn get_flow_results < ' a , ' tcx > (
0 commit comments