@@ -71,7 +71,7 @@ pub(crate) enum PlaceBase {
71
71
/// This is used internally when building a place for an expression like `a.b.c`. The fields `b`
72
72
/// and `c` can be progressively pushed onto the place builder that is created when converting `a`.
73
73
#[ derive( Clone , Debug , PartialEq ) ]
74
- pub ( crate ) struct PlaceBuilder < ' tcx > {
74
+ pub ( in crate :: build ) struct PlaceBuilder < ' tcx > {
75
75
base : PlaceBase ,
76
76
projection : Vec < PlaceElem < ' tcx > > ,
77
77
}
@@ -202,10 +202,9 @@ fn find_capture_matching_projections<'a, 'tcx>(
202
202
/// `PlaceBuilder` now starts from `PlaceBase::Local`.
203
203
///
204
204
/// 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 > (
206
206
from_builder : PlaceBuilder < ' tcx > ,
207
- tcx : TyCtxt < ' tcx > ,
208
- typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
207
+ cx : & Builder < ' _ , ' tcx > ,
209
208
) -> Result < PlaceBuilder < ' tcx > , PlaceBuilder < ' tcx > > {
210
209
match from_builder. base {
211
210
PlaceBase :: Local ( _) => Ok ( from_builder) ,
@@ -220,13 +219,13 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
220
219
221
220
let Some ( ( capture_index, capture) ) =
222
221
find_capture_matching_projections (
223
- typeck_results,
222
+ cx . typeck_results ,
224
223
var_hir_id,
225
224
closure_def_id,
226
225
& from_builder. projection ,
227
226
) 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) {
230
229
bug ! (
231
230
"No associated capture found for {:?}[{:#?}] even though \
232
231
capture_disjoint_fields isn't enabled",
@@ -243,8 +242,8 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
243
242
} ;
244
243
245
244
// 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) ;
248
247
249
248
let substs = match closure_ty. kind ( ) {
250
249
ty:: Closure ( _, substs) => ty:: UpvarSubsts :: Closure ( substs) ,
@@ -316,24 +315,16 @@ fn strip_prefix<'tcx>(
316
315
}
317
316
318
317
impl < ' 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 > {
324
319
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 ) }
326
321
} else {
327
- self . expect_upvars_resolved ( tcx , typeck_results ) . into_place ( tcx , typeck_results )
322
+ self . expect_upvars_resolved ( cx ) . into_place ( cx )
328
323
}
329
324
}
330
325
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 ( )
337
328
}
338
329
339
330
/// Attempts to resolve the `PlaceBuilder`.
@@ -347,12 +338,11 @@ impl<'tcx> PlaceBuilder<'tcx> {
347
338
/// not captured. This can happen because the final mir that will be
348
339
/// generated doesn't require a read for this place. Failures will only
349
340
/// happen inside closures.
350
- pub ( crate ) fn try_upvars_resolved < ' a > (
341
+ pub ( crate ) fn try_upvars_resolved (
351
342
self ,
352
- tcx : TyCtxt < ' tcx > ,
353
- typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
343
+ cx : & Builder < ' _ , ' tcx > ,
354
344
) -> Result < PlaceBuilder < ' tcx > , PlaceBuilder < ' tcx > > {
355
- to_upvars_resolved_place_builder ( self , tcx , typeck_results )
345
+ to_upvars_resolved_place_builder ( self , cx )
356
346
}
357
347
358
348
pub ( crate ) fn base ( & self ) -> PlaceBase {
@@ -412,7 +402,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
412
402
expr : & Expr < ' tcx > ,
413
403
) -> BlockAnd < Place < ' tcx > > {
414
404
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 ) )
416
406
}
417
407
418
408
/// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -436,7 +426,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
436
426
expr : & Expr < ' tcx > ,
437
427
) -> BlockAnd < Place < ' tcx > > {
438
428
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 ) )
440
430
}
441
431
442
432
/// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -531,7 +521,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
531
521
inferred_ty : expr. ty ,
532
522
} ) ;
533
523
534
- let place = place_builder. clone ( ) . into_place ( this. tcx , this . typeck_results ) ;
524
+ let place = place_builder. clone ( ) . into_place ( this) ;
535
525
this. cfg . push (
536
526
block,
537
527
Statement {
@@ -683,7 +673,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
683
673
if is_outermost_index {
684
674
self . read_fake_borrows ( block, fake_borrow_temps, source_info)
685
675
} else {
686
- base_place = base_place. expect_upvars_resolved ( self . tcx , self . typeck_results ) ;
676
+ base_place = base_place. expect_upvars_resolved ( self ) ;
687
677
self . add_fake_borrows_of_base (
688
678
& base_place,
689
679
block,
@@ -711,12 +701,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
711
701
let lt = self . temp ( bool_ty, expr_span) ;
712
702
713
703
// 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 ) ) ) ;
720
705
// lt = idx < len
721
706
self . cfg . push_assign (
722
707
block,
0 commit comments