@@ -71,7 +71,7 @@ pub(crate) enum PlaceBase {
7171/// This is used internally when building a place for an expression like `a.b.c`. The fields `b`
7272/// and `c` can be progressively pushed onto the place builder that is created when converting `a`.
7373#[ derive( Clone , Debug , PartialEq ) ]
74- pub ( crate ) struct PlaceBuilder < ' tcx > {
74+ pub ( in crate :: build ) struct PlaceBuilder < ' tcx > {
7575 base : PlaceBase ,
7676 projection : Vec < PlaceElem < ' tcx > > ,
7777}
@@ -202,10 +202,9 @@ fn find_capture_matching_projections<'a, 'tcx>(
202202/// `PlaceBuilder` now starts from `PlaceBase::Local`.
203203///
204204/// Returns a Result with the error being the PlaceBuilder (`from_builder`) that was not found.
205- fn to_upvars_resolved_place_builder < ' a , ' tcx > (
205+ fn to_upvars_resolved_place_builder < ' tcx > (
206206 from_builder : PlaceBuilder < ' tcx > ,
207- tcx : TyCtxt < ' tcx > ,
208- typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
207+ cx : & Builder < ' _ , ' tcx > ,
209208) -> Result < PlaceBuilder < ' tcx > , PlaceBuilder < ' tcx > > {
210209 match from_builder. base {
211210 PlaceBase :: Local ( _) => Ok ( from_builder) ,
@@ -220,13 +219,13 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
220219
221220 let Some ( ( capture_index, capture) ) =
222221 find_capture_matching_projections (
223- typeck_results,
222+ cx . typeck_results ,
224223 var_hir_id,
225224 closure_def_id,
226225 & from_builder. projection ,
227226 ) else {
228- let closure_span = tcx. def_span ( closure_def_id) ;
229- if !enable_precise_capture ( tcx, closure_span) {
227+ let closure_span = cx . tcx . def_span ( closure_def_id) ;
228+ if !enable_precise_capture ( cx . tcx , closure_span) {
230229 bug ! (
231230 "No associated capture found for {:?}[{:#?}] even though \
232231 capture_disjoint_fields isn't enabled",
@@ -243,8 +242,8 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
243242 } ;
244243
245244 // We won't be building MIR if the closure wasn't local
246- let closure_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( closure_def_id. expect_local ( ) ) ;
247- let closure_ty = typeck_results. node_type ( closure_hir_id) ;
245+ let closure_hir_id = cx . tcx . hir ( ) . local_def_id_to_hir_id ( closure_def_id. expect_local ( ) ) ;
246+ let closure_ty = cx . typeck_results . node_type ( closure_hir_id) ;
248247
249248 let substs = match closure_ty. kind ( ) {
250249 ty:: Closure ( _, substs) => ty:: UpvarSubsts :: Closure ( substs) ,
@@ -316,24 +315,16 @@ fn strip_prefix<'tcx>(
316315}
317316
318317impl < ' tcx > PlaceBuilder < ' tcx > {
319- pub ( crate ) fn into_place < ' a > (
320- self ,
321- tcx : TyCtxt < ' tcx > ,
322- typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
323- ) -> Place < ' tcx > {
318+ pub ( crate ) fn into_place ( self , cx : & Builder < ' _ , ' tcx > ) -> Place < ' tcx > {
324319 if let PlaceBase :: Local ( local) = self . base {
325- Place { local, projection : tcx. intern_place_elems ( & self . projection ) }
320+ Place { local, projection : cx . tcx . intern_place_elems ( & self . projection ) }
326321 } else {
327- self . expect_upvars_resolved ( tcx , typeck_results ) . into_place ( tcx , typeck_results )
322+ self . expect_upvars_resolved ( cx ) . into_place ( cx )
328323 }
329324 }
330325
331- fn expect_upvars_resolved < ' a > (
332- self ,
333- tcx : TyCtxt < ' tcx > ,
334- typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
335- ) -> PlaceBuilder < ' tcx > {
336- to_upvars_resolved_place_builder ( self , tcx, typeck_results) . unwrap ( )
326+ fn expect_upvars_resolved ( self , cx : & Builder < ' _ , ' tcx > ) -> PlaceBuilder < ' tcx > {
327+ to_upvars_resolved_place_builder ( self , cx) . unwrap ( )
337328 }
338329
339330 /// Attempts to resolve the `PlaceBuilder`.
@@ -347,12 +338,11 @@ impl<'tcx> PlaceBuilder<'tcx> {
347338 /// not captured. This can happen because the final mir that will be
348339 /// generated doesn't require a read for this place. Failures will only
349340 /// happen inside closures.
350- pub ( crate ) fn try_upvars_resolved < ' a > (
341+ pub ( crate ) fn try_upvars_resolved (
351342 self ,
352- tcx : TyCtxt < ' tcx > ,
353- typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
343+ cx : & Builder < ' _ , ' tcx > ,
354344 ) -> Result < PlaceBuilder < ' tcx > , PlaceBuilder < ' tcx > > {
355- to_upvars_resolved_place_builder ( self , tcx , typeck_results )
345+ to_upvars_resolved_place_builder ( self , cx )
356346 }
357347
358348 pub ( crate ) fn base ( & self ) -> PlaceBase {
@@ -412,7 +402,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
412402 expr : & Expr < ' tcx > ,
413403 ) -> BlockAnd < Place < ' tcx > > {
414404 let place_builder = unpack ! ( block = self . as_place_builder( block, expr) ) ;
415- block. and ( place_builder. into_place ( self . tcx , self . typeck_results ) )
405+ block. and ( place_builder. into_place ( self ) )
416406 }
417407
418408 /// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -436,7 +426,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
436426 expr : & Expr < ' tcx > ,
437427 ) -> BlockAnd < Place < ' tcx > > {
438428 let place_builder = unpack ! ( block = self . as_read_only_place_builder( block, expr) ) ;
439- block. and ( place_builder. into_place ( self . tcx , self . typeck_results ) )
429+ block. and ( place_builder. into_place ( self ) )
440430 }
441431
442432 /// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -531,7 +521,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
531521 inferred_ty : expr. ty ,
532522 } ) ;
533523
534- let place = place_builder. clone ( ) . into_place ( this. tcx , this . typeck_results ) ;
524+ let place = place_builder. clone ( ) . into_place ( this) ;
535525 this. cfg . push (
536526 block,
537527 Statement {
@@ -683,7 +673,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
683673 if is_outermost_index {
684674 self . read_fake_borrows ( block, fake_borrow_temps, source_info)
685675 } else {
686- base_place = base_place. expect_upvars_resolved ( self . tcx , self . typeck_results ) ;
676+ base_place = base_place. expect_upvars_resolved ( self ) ;
687677 self . add_fake_borrows_of_base (
688678 & base_place,
689679 block,
@@ -711,12 +701,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
711701 let lt = self . temp ( bool_ty, expr_span) ;
712702
713703 // len = len(slice)
714- self . cfg . push_assign (
715- block,
716- source_info,
717- len,
718- Rvalue :: Len ( slice. into_place ( self . tcx , self . typeck_results ) ) ,
719- ) ;
704+ self . cfg . push_assign ( block, source_info, len, Rvalue :: Len ( slice. into_place ( self ) ) ) ;
720705 // lt = idx < len
721706 self . cfg . push_assign (
722707 block,
0 commit comments