@@ -69,7 +69,7 @@ pub(crate) enum PlaceBase {
6969/// This is used internally when building a place for an expression like `a.b.c`. The fields `b`
7070/// and `c` can be progressively pushed onto the place builder that is created when converting `a`.
7171#[ derive( Clone , Debug , PartialEq ) ]
72- pub ( crate ) struct PlaceBuilder < ' tcx > {
72+ pub ( in crate :: build ) struct PlaceBuilder < ' tcx > {
7373 base : PlaceBase ,
7474 projection : Vec < PlaceElem < ' tcx > > ,
7575}
@@ -168,22 +168,22 @@ fn find_capture_matching_projections<'a, 'tcx>(
168168/// `PlaceBuilder` now starts from `PlaceBase::Local`.
169169///
170170/// Returns a Result with the error being the PlaceBuilder (`from_builder`) that was not found.
171- fn to_upvars_resolved_place_builder < ' a , ' tcx > (
171+ #[ instrument( level = "trace" , skip( cx) ) ]
172+ fn to_upvars_resolved_place_builder < ' tcx > (
172173 from_builder : PlaceBuilder < ' tcx > ,
173- tcx : TyCtxt < ' tcx > ,
174- upvars : & ' a CaptureMap < ' tcx > ,
174+ cx : & Builder < ' _ , ' tcx > ,
175175) -> Result < PlaceBuilder < ' tcx > , PlaceBuilder < ' tcx > > {
176176 match from_builder. base {
177177 PlaceBase :: Local ( _) => Ok ( from_builder) ,
178178 PlaceBase :: Upvar { var_hir_id, closure_def_id } => {
179179 let Some ( ( capture_index, capture) ) =
180180 find_capture_matching_projections (
181- upvars,
181+ & cx . upvars ,
182182 var_hir_id,
183183 & from_builder. projection ,
184184 ) else {
185- let closure_span = tcx. def_span ( closure_def_id) ;
186- if !enable_precise_capture ( tcx, closure_span) {
185+ let closure_span = cx . tcx . def_span ( closure_def_id) ;
186+ if !enable_precise_capture ( cx . tcx , closure_span) {
187187 bug ! (
188188 "No associated capture found for {:?}[{:#?}] even though \
189189 capture_disjoint_fields isn't enabled",
@@ -200,18 +200,20 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
200200 } ;
201201
202202 // Access the capture by accessing the field within the Closure struct.
203- let capture_info = & upvars[ capture_index] ;
203+ let capture_info = & cx . upvars [ capture_index] ;
204204
205205 let mut upvar_resolved_place_builder = PlaceBuilder :: from ( capture_info. use_place ) ;
206206
207207 // We used some of the projections to build the capture itself,
208208 // now we apply the remaining to the upvar resolved place.
209+ trace ! ( ?capture. captured_place, ?from_builder. projection) ;
209210 let remaining_projections = strip_prefix (
210211 capture. captured_place . place . base_ty ,
211212 from_builder. projection ,
212213 & capture. captured_place . place . projections ,
213214 ) ;
214215 upvar_resolved_place_builder. projection . extend ( remaining_projections) ;
216+ trace ! ( ?upvar_resolved_place_builder) ;
215217
216218 Ok ( upvar_resolved_place_builder)
217219 }
@@ -251,24 +253,16 @@ fn strip_prefix<'tcx>(
251253}
252254
253255impl < ' tcx > PlaceBuilder < ' tcx > {
254- pub ( in crate :: build) fn into_place < ' a > (
255- self ,
256- tcx : TyCtxt < ' tcx > ,
257- upvars : & ' a CaptureMap < ' tcx > ,
258- ) -> Place < ' tcx > {
256+ pub ( in crate :: build) fn into_place ( self , cx : & Builder < ' _ , ' tcx > ) -> Place < ' tcx > {
259257 if let PlaceBase :: Local ( local) = self . base {
260- Place { local, projection : tcx. intern_place_elems ( & self . projection ) }
258+ Place { local, projection : cx . tcx . intern_place_elems ( & self . projection ) }
261259 } else {
262- self . expect_upvars_resolved ( tcx , upvars ) . into_place ( tcx , upvars )
260+ self . expect_upvars_resolved ( cx ) . into_place ( cx )
263261 }
264262 }
265263
266- fn expect_upvars_resolved < ' a > (
267- self ,
268- tcx : TyCtxt < ' tcx > ,
269- upvars : & ' a CaptureMap < ' tcx > ,
270- ) -> PlaceBuilder < ' tcx > {
271- to_upvars_resolved_place_builder ( self , tcx, upvars) . unwrap ( )
264+ fn expect_upvars_resolved ( self , cx : & Builder < ' _ , ' tcx > ) -> PlaceBuilder < ' tcx > {
265+ to_upvars_resolved_place_builder ( self , cx) . unwrap ( )
272266 }
273267
274268 /// Attempts to resolve the `PlaceBuilder`.
@@ -282,12 +276,11 @@ impl<'tcx> PlaceBuilder<'tcx> {
282276 /// not captured. This can happen because the final mir that will be
283277 /// generated doesn't require a read for this place. Failures will only
284278 /// happen inside closures.
285- pub ( in crate :: build) fn try_upvars_resolved < ' a > (
279+ pub ( in crate :: build) fn try_upvars_resolved (
286280 self ,
287- tcx : TyCtxt < ' tcx > ,
288- upvars : & ' a CaptureMap < ' tcx > ,
281+ cx : & Builder < ' _ , ' tcx > ,
289282 ) -> Result < PlaceBuilder < ' tcx > , PlaceBuilder < ' tcx > > {
290- to_upvars_resolved_place_builder ( self , tcx , upvars )
283+ to_upvars_resolved_place_builder ( self , cx )
291284 }
292285
293286 pub ( crate ) fn base ( & self ) -> PlaceBase {
@@ -353,7 +346,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
353346 expr : & Expr < ' tcx > ,
354347 ) -> BlockAnd < Place < ' tcx > > {
355348 let place_builder = unpack ! ( block = self . as_place_builder( block, expr) ) ;
356- block. and ( place_builder. into_place ( self . tcx , & self . upvars ) )
349+ block. and ( place_builder. into_place ( self ) )
357350 }
358351
359352 /// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -377,7 +370,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
377370 expr : & Expr < ' tcx > ,
378371 ) -> BlockAnd < Place < ' tcx > > {
379372 let place_builder = unpack ! ( block = self . as_read_only_place_builder( block, expr) ) ;
380- block. and ( place_builder. into_place ( self . tcx , & self . upvars ) )
373+ block. and ( place_builder. into_place ( self ) )
381374 }
382375
383376 /// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -472,7 +465,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
472465 inferred_ty : expr. ty ,
473466 } ) ;
474467
475- let place = place_builder. clone ( ) . into_place ( this. tcx , & this . upvars ) ;
468+ let place = place_builder. clone ( ) . into_place ( this) ;
476469 this. cfg . push (
477470 block,
478471 Statement {
@@ -610,7 +603,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
610603 if is_outermost_index {
611604 self . read_fake_borrows ( block, fake_borrow_temps, source_info)
612605 } else {
613- base_place = base_place. expect_upvars_resolved ( self . tcx , & self . upvars ) ;
606+ base_place = base_place. expect_upvars_resolved ( self ) ;
614607 self . add_fake_borrows_of_base (
615608 & base_place,
616609 block,
@@ -638,12 +631,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
638631 let lt = self . temp ( bool_ty, expr_span) ;
639632
640633 // len = len(slice)
641- self . cfg . push_assign (
642- block,
643- source_info,
644- len,
645- Rvalue :: Len ( slice. into_place ( self . tcx , & self . upvars ) ) ,
646- ) ;
634+ self . cfg . push_assign ( block, source_info, len, Rvalue :: Len ( slice. into_place ( self ) ) ) ;
647635 // lt = idx < len
648636 self . cfg . push_assign (
649637 block,
0 commit comments