@@ -23,9 +23,8 @@ use rustc_hir as hir;
2323use rustc_hir:: def_id:: LocalDefId ;
2424use rustc_index:: bit_set:: { BitSet , ChunkedBitSet } ;
2525use rustc_index:: { IndexSlice , IndexVec } ;
26- use rustc_infer:: infer:: {
27- InferCtxt , NllRegionVariableOrigin , RegionVariableOrigin , TyCtxtInferExt ,
28- } ;
26+ use rustc_infer:: infer:: TyCtxtInferExt ;
27+ use rustc_infer:: infer:: { InferCtxt , NllRegionVariableOrigin , RegionVariableOrigin } ;
2928use rustc_middle:: mir:: tcx:: PlaceTy ;
3029use rustc_middle:: mir:: * ;
3130use rustc_middle:: query:: Providers ;
@@ -123,9 +122,8 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
123122 return tcx. arena . alloc ( result) ;
124123 }
125124
126- let infcx = tcx. infer_ctxt ( ) . with_opaque_type_inference ( def) . build ( ) ;
127125 let promoted: & IndexSlice < _ , _ > = & promoted. borrow ( ) ;
128- let opt_closure_req = do_mir_borrowck ( & infcx , input_body, promoted, None ) . 0 ;
126+ let opt_closure_req = do_mir_borrowck ( tcx , input_body, promoted, None ) . 0 ;
129127 debug ! ( "mir_borrowck done" ) ;
130128
131129 tcx. arena . alloc ( opt_closure_req)
@@ -136,18 +134,15 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
136134/// Use `consumer_options: None` for the default behavior of returning
137135/// [`BorrowCheckResult`] only. Otherwise, return [`BodyWithBorrowckFacts`] according
138136/// to the given [`ConsumerOptions`].
139- #[ instrument( skip( infcx , input_body, input_promoted) , fields( id=?input_body. source. def_id( ) ) , level = "debug" ) ]
137+ #[ instrument( skip( tcx , input_body, input_promoted) , fields( id=?input_body. source. def_id( ) ) , level = "debug" ) ]
140138fn do_mir_borrowck < ' tcx > (
141- infcx : & InferCtxt < ' tcx > ,
139+ tcx : TyCtxt < ' tcx > ,
142140 input_body : & Body < ' tcx > ,
143141 input_promoted : & IndexSlice < Promoted , Body < ' tcx > > ,
144142 consumer_options : Option < ConsumerOptions > ,
145143) -> ( BorrowCheckResult < ' tcx > , Option < Box < BodyWithBorrowckFacts < ' tcx > > > ) {
146144 let def = input_body. source . def_id ( ) . expect_local ( ) ;
147- debug ! ( ?def) ;
148-
149- let tcx = infcx. tcx ;
150- let infcx = BorrowckInferCtxt :: new ( infcx) ;
145+ let infcx = BorrowckInferCtxt :: new ( tcx, def) ;
151146 let param_env = tcx. param_env ( def) ;
152147
153148 let mut local_names = IndexVec :: from_elem ( None , & input_body. local_decls ) ;
@@ -440,13 +435,14 @@ fn do_mir_borrowck<'tcx>(
440435 ( result, body_with_facts)
441436}
442437
443- pub struct BorrowckInferCtxt < ' cx , ' tcx > {
444- pub ( crate ) infcx : & ' cx InferCtxt < ' tcx > ,
438+ pub struct BorrowckInferCtxt < ' tcx > {
439+ pub ( crate ) infcx : InferCtxt < ' tcx > ,
445440 pub ( crate ) reg_var_to_origin : RefCell < FxIndexMap < ty:: RegionVid , RegionCtxt > > ,
446441}
447442
448- impl < ' cx , ' tcx > BorrowckInferCtxt < ' cx , ' tcx > {
449- pub ( crate ) fn new ( infcx : & ' cx InferCtxt < ' tcx > ) -> Self {
443+ impl < ' tcx > BorrowckInferCtxt < ' tcx > {
444+ pub ( crate ) fn new ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> Self {
445+ let infcx = tcx. infer_ctxt ( ) . with_opaque_type_inference ( def_id) . build ( ) ;
450446 BorrowckInferCtxt { infcx, reg_var_to_origin : RefCell :: new ( Default :: default ( ) ) }
451447 }
452448
@@ -494,16 +490,16 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
494490 }
495491}
496492
497- impl < ' cx , ' tcx > Deref for BorrowckInferCtxt < ' cx , ' tcx > {
493+ impl < ' tcx > Deref for BorrowckInferCtxt < ' tcx > {
498494 type Target = InferCtxt < ' tcx > ;
499495
500- fn deref ( & self ) -> & ' cx Self :: Target {
501- self . infcx
496+ fn deref ( & self ) -> & Self :: Target {
497+ & self . infcx
502498 }
503499}
504500
505501struct MirBorrowckCtxt < ' cx , ' tcx > {
506- infcx : & ' cx BorrowckInferCtxt < ' cx , ' tcx > ,
502+ infcx : & ' cx BorrowckInferCtxt < ' tcx > ,
507503 param_env : ParamEnv < ' tcx > ,
508504 body : & ' cx Body < ' tcx > ,
509505 move_data : & ' cx MoveData < ' tcx > ,
0 commit comments