@@ -62,6 +62,7 @@ use crate::session_diagnostics::VarNeedNotMut;
6262use self :: diagnostics:: { AccessKind , RegionName } ;
6363use self :: location:: LocationTable ;
6464use self :: prefixes:: PrefixSet ;
65+ use consumers:: ConsumerOptions ;
6566use facts:: AllFacts ;
6667
6768use self :: path_utils:: * ;
@@ -144,23 +145,23 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
144145 tcx. infer_ctxt ( ) . with_opaque_type_inference ( DefiningAnchor :: Bind ( hir_owner. def_id ) ) . build ( ) ;
145146 let input_body: & Body < ' _ > = & input_body. borrow ( ) ;
146147 let promoted: & IndexSlice < _ , _ > = & promoted. borrow ( ) ;
147- let opt_closure_req = do_mir_borrowck ( & infcx, input_body, promoted, false ) . 0 ;
148+ let opt_closure_req = do_mir_borrowck ( & infcx, input_body, promoted, None ) . 0 ;
148149 debug ! ( "mir_borrowck done" ) ;
149150
150151 tcx. arena . alloc ( opt_closure_req)
151152}
152153
153154/// Perform the actual borrow checking.
154155///
155- /// If `return_body_with_facts` is true, then return the body with non-erased
156- /// region ids on which the borrow checking was performed together with Polonius
157- /// facts .
156+ /// Use `consumer_options: None` for the default behavior of returning
157+ /// [`BorrowCheckResult`] only. Otherwise, return [`BodyWithBorrowckFacts`] according
158+ /// to the given [`ConsumerOptions`] .
158159#[ instrument( skip( infcx, input_body, input_promoted) , fields( id=?input_body. source. def_id( ) ) , level = "debug" ) ]
159160fn do_mir_borrowck < ' tcx > (
160161 infcx : & InferCtxt < ' tcx > ,
161162 input_body : & Body < ' tcx > ,
162163 input_promoted : & IndexSlice < Promoted , Body < ' tcx > > ,
163- return_body_with_facts : bool ,
164+ consumer_options : Option < ConsumerOptions > ,
164165) -> ( BorrowCheckResult < ' tcx > , Option < Box < BodyWithBorrowckFacts < ' tcx > > > ) {
165166 let def = input_body. source . def_id ( ) . expect_local ( ) ;
166167 debug ! ( ?def) ;
@@ -241,8 +242,6 @@ fn do_mir_borrowck<'tcx>(
241242 let borrow_set =
242243 Rc :: new ( BorrowSet :: build ( tcx, body, locals_are_invalidated_at_exit, & mdpe. move_data ) ) ;
243244
244- let use_polonius = return_body_with_facts || infcx. tcx . sess . opts . unstable_opts . polonius ;
245-
246245 // Compute non-lexical lifetimes.
247246 let nll:: NllOutput {
248247 regioncx,
@@ -262,7 +261,7 @@ fn do_mir_borrowck<'tcx>(
262261 & mdpe. move_data ,
263262 & borrow_set,
264263 & upvars,
265- use_polonius ,
264+ consumer_options ,
266265 ) ;
267266
268267 // Dump MIR results into a file, if that is enabled. This let us
@@ -444,13 +443,15 @@ fn do_mir_borrowck<'tcx>(
444443 tainted_by_errors,
445444 } ;
446445
447- let body_with_facts = if return_body_with_facts {
448- let output_facts = mbcx. polonius_output . expect ( "Polonius output was not computed" ) ;
446+ let body_with_facts = if consumer_options . is_some ( ) {
447+ let output_facts = mbcx. polonius_output ;
449448 Some ( Box :: new ( BodyWithBorrowckFacts {
450449 body : body_owned,
451- input_facts : * polonius_input. expect ( "Polonius input facts were not generated" ) ,
450+ borrow_set,
451+ region_inference_context : regioncx,
452+ location_table : polonius_input. as_ref ( ) . map ( |_| location_table_owned) ,
453+ input_facts : polonius_input,
452454 output_facts,
453- location_table : location_table_owned,
454455 } ) )
455456 } else {
456457 None
@@ -469,12 +470,20 @@ fn do_mir_borrowck<'tcx>(
469470pub struct BodyWithBorrowckFacts < ' tcx > {
470471 /// A mir body that contains region identifiers.
471472 pub body : Body < ' tcx > ,
472- /// Polonius input facts.
473- pub input_facts : AllFacts ,
474- /// Polonius output facts.
475- pub output_facts : Rc < self :: nll:: PoloniusOutput > ,
476- /// The table that maps Polonius points to locations in the table.
477- pub location_table : LocationTable ,
473+ /// The set of borrows occurring in `body` with data about them.
474+ pub borrow_set : Rc < BorrowSet < ' tcx > > ,
475+ /// Context generated during borrowck, intended to be passed to
476+ /// [`OutOfScopePrecomputer`](dataflow::OutOfScopePrecomputer).
477+ pub region_inference_context : Rc < RegionInferenceContext < ' tcx > > ,
478+ /// The table that maps Polonius points to locations in the table. Populated
479+ /// when using [`ConsumerOptions::PoloniusInputFacts`] or above.
480+ pub location_table : Option < LocationTable > ,
481+ /// Polonius input facts. Populated when using
482+ /// [`ConsumerOptions::PoloniusInputFacts`] or above.
483+ pub input_facts : Option < Box < AllFacts > > ,
484+ /// Polonius output facts. Populated when using
485+ /// [`ConsumerOptions::PoloniusOutputFacts`] or above.
486+ pub output_facts : Option < Rc < self :: nll:: PoloniusOutput > > ,
478487}
479488
480489pub struct BorrowckInferCtxt < ' cx , ' tcx > {
0 commit comments