@@ -69,7 +69,7 @@ pub(crate) enum PlaceBase {
69
69
/// This is used internally when building a place for an expression like `a.b.c`. The fields `b`
70
70
/// and `c` can be progressively pushed onto the place builder that is created when converting `a`.
71
71
#[ derive( Clone , Debug , PartialEq ) ]
72
- pub ( crate ) struct PlaceBuilder < ' tcx > {
72
+ pub ( in crate :: build ) struct PlaceBuilder < ' tcx > {
73
73
base : PlaceBase ,
74
74
projection : Vec < PlaceElem < ' tcx > > ,
75
75
}
@@ -168,22 +168,22 @@ fn find_capture_matching_projections<'a, 'tcx>(
168
168
/// `PlaceBuilder` now starts from `PlaceBase::Local`.
169
169
///
170
170
/// 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 > (
172
173
from_builder : PlaceBuilder < ' tcx > ,
173
- tcx : TyCtxt < ' tcx > ,
174
- upvars : & ' a CaptureMap < ' tcx > ,
174
+ cx : & Builder < ' _ , ' tcx > ,
175
175
) -> Result < PlaceBuilder < ' tcx > , PlaceBuilder < ' tcx > > {
176
176
match from_builder. base {
177
177
PlaceBase :: Local ( _) => Ok ( from_builder) ,
178
178
PlaceBase :: Upvar { var_hir_id, closure_def_id } => {
179
179
let Some ( ( capture_index, capture) ) =
180
180
find_capture_matching_projections (
181
- upvars,
181
+ & cx . upvars ,
182
182
var_hir_id,
183
183
& from_builder. projection ,
184
184
) 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) {
187
187
bug ! (
188
188
"No associated capture found for {:?}[{:#?}] even though \
189
189
capture_disjoint_fields isn't enabled",
@@ -200,18 +200,20 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
200
200
} ;
201
201
202
202
// 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] ;
204
204
205
205
let mut upvar_resolved_place_builder = PlaceBuilder :: from ( capture_info. use_place ) ;
206
206
207
207
// We used some of the projections to build the capture itself,
208
208
// now we apply the remaining to the upvar resolved place.
209
+ trace ! ( ?capture. captured_place, ?from_builder. projection) ;
209
210
let remaining_projections = strip_prefix (
210
211
capture. captured_place . place . base_ty ,
211
212
from_builder. projection ,
212
213
& capture. captured_place . place . projections ,
213
214
) ;
214
215
upvar_resolved_place_builder. projection . extend ( remaining_projections) ;
216
+ trace ! ( ?upvar_resolved_place_builder) ;
215
217
216
218
Ok ( upvar_resolved_place_builder)
217
219
}
@@ -251,24 +253,16 @@ fn strip_prefix<'tcx>(
251
253
}
252
254
253
255
impl < ' 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 > {
259
257
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 ) }
261
259
} else {
262
- self . expect_upvars_resolved ( tcx , upvars ) . into_place ( tcx , upvars )
260
+ self . expect_upvars_resolved ( cx ) . into_place ( cx )
263
261
}
264
262
}
265
263
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 ( )
272
266
}
273
267
274
268
/// Attempts to resolve the `PlaceBuilder`.
@@ -282,12 +276,11 @@ impl<'tcx> PlaceBuilder<'tcx> {
282
276
/// not captured. This can happen because the final mir that will be
283
277
/// generated doesn't require a read for this place. Failures will only
284
278
/// happen inside closures.
285
- pub ( in crate :: build) fn try_upvars_resolved < ' a > (
279
+ pub ( in crate :: build) fn try_upvars_resolved (
286
280
self ,
287
- tcx : TyCtxt < ' tcx > ,
288
- upvars : & ' a CaptureMap < ' tcx > ,
281
+ cx : & Builder < ' _ , ' tcx > ,
289
282
) -> Result < PlaceBuilder < ' tcx > , PlaceBuilder < ' tcx > > {
290
- to_upvars_resolved_place_builder ( self , tcx , upvars )
283
+ to_upvars_resolved_place_builder ( self , cx )
291
284
}
292
285
293
286
pub ( crate ) fn base ( & self ) -> PlaceBase {
@@ -353,7 +346,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
353
346
expr : & Expr < ' tcx > ,
354
347
) -> BlockAnd < Place < ' tcx > > {
355
348
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 ) )
357
350
}
358
351
359
352
/// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -377,7 +370,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
377
370
expr : & Expr < ' tcx > ,
378
371
) -> BlockAnd < Place < ' tcx > > {
379
372
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 ) )
381
374
}
382
375
383
376
/// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -472,7 +465,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
472
465
inferred_ty : expr. ty ,
473
466
} ) ;
474
467
475
- let place = place_builder. clone ( ) . into_place ( this. tcx , & this . upvars ) ;
468
+ let place = place_builder. clone ( ) . into_place ( this) ;
476
469
this. cfg . push (
477
470
block,
478
471
Statement {
@@ -610,7 +603,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
610
603
if is_outermost_index {
611
604
self . read_fake_borrows ( block, fake_borrow_temps, source_info)
612
605
} else {
613
- base_place = base_place. expect_upvars_resolved ( self . tcx , & self . upvars ) ;
606
+ base_place = base_place. expect_upvars_resolved ( self ) ;
614
607
self . add_fake_borrows_of_base (
615
608
& base_place,
616
609
block,
@@ -638,12 +631,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
638
631
let lt = self . temp ( bool_ty, expr_span) ;
639
632
640
633
// 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 ) ) ) ;
647
635
// lt = idx < len
648
636
self . cfg . push_assign (
649
637
block,
0 commit comments