@@ -65,7 +65,7 @@ pub(crate) enum PlaceBase {
65
65
66
66
/// `PlaceBuilder` is used to create places during MIR construction. It allows you to "build up" a
67
67
/// place by pushing more and more projections onto the end, and then convert the final set into a
68
- /// place using the `into_place ` method.
68
+ /// place using the `to_place ` method.
69
69
///
70
70
/// This is used internally when building a place for an expression like `a.b.c`. The fields `b`
71
71
/// and `c` can be progressively pushed onto the place builder that is created when converting `a`.
@@ -254,17 +254,8 @@ fn strip_prefix<'a, 'tcx>(
254
254
}
255
255
256
256
impl < ' tcx > PlaceBuilder < ' tcx > {
257
- pub ( in crate :: build) fn into_place ( mut self , cx : & Builder < ' _ , ' tcx > ) -> Place < ' tcx > {
258
- self = self . resolve_upvar ( cx) . unwrap_or ( self ) ;
259
- let PlaceBase :: Local ( local) = self . base else { panic ! ( "expected local" ) } ;
260
- Place { local, projection : cx. tcx . intern_place_elems ( & self . projection ) }
261
- }
262
-
263
- fn expect_upvars_resolved ( self , cx : & Builder < ' _ , ' tcx > ) -> PlaceBuilder < ' tcx > {
264
- match self . base {
265
- PlaceBase :: Local ( _) => self ,
266
- PlaceBase :: Upvar { ..} => self . resolve_upvar ( cx) . unwrap ( ) ,
267
- }
257
+ pub ( in crate :: build) fn to_place ( & self , cx : & Builder < ' _ , ' tcx > ) -> Place < ' tcx > {
258
+ self . try_to_place ( cx) . unwrap ( )
268
259
}
269
260
270
261
/// Creates a `Place` or returns `None` if an upvar cannot be resolved
@@ -363,7 +354,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
363
354
expr : & Expr < ' tcx > ,
364
355
) -> BlockAnd < Place < ' tcx > > {
365
356
let place_builder = unpack ! ( block = self . as_place_builder( block, expr) ) ;
366
- block. and ( place_builder. into_place ( self ) )
357
+ block. and ( place_builder. to_place ( self ) )
367
358
}
368
359
369
360
/// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -387,7 +378,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
387
378
expr : & Expr < ' tcx > ,
388
379
) -> BlockAnd < Place < ' tcx > > {
389
380
let place_builder = unpack ! ( block = self . as_read_only_place_builder( block, expr) ) ;
390
- block. and ( place_builder. into_place ( self ) )
381
+ block. and ( place_builder. to_place ( self ) )
391
382
}
392
383
393
384
/// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -482,7 +473,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
482
473
inferred_ty : expr. ty ,
483
474
} ) ;
484
475
485
- let place = place_builder. clone ( ) . into_place ( this) ;
476
+ let place = place_builder. to_place ( this) ;
486
477
this. cfg . push (
487
478
block,
488
479
Statement {
@@ -607,22 +598,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
607
598
let is_outermost_index = fake_borrow_temps. is_none ( ) ;
608
599
let fake_borrow_temps = fake_borrow_temps. unwrap_or ( base_fake_borrow_temps) ;
609
600
610
- let mut base_place =
601
+ let base_place =
611
602
unpack ! ( block = self . expr_as_place( block, base, mutability, Some ( fake_borrow_temps) , ) ) ;
612
603
613
604
// Making this a *fresh* temporary means we do not have to worry about
614
605
// the index changing later: Nothing will ever change this temporary.
615
606
// The "retagging" transformation (for Stacked Borrows) relies on this.
616
607
let idx = unpack ! ( block = self . as_temp( block, temp_lifetime, index, Mutability :: Not , ) ) ;
617
608
618
- block = self . bounds_check ( block, base_place. clone ( ) , idx, expr_span, source_info) ;
609
+ block = self . bounds_check ( block, & base_place, idx, expr_span, source_info) ;
619
610
620
611
if is_outermost_index {
621
612
self . read_fake_borrows ( block, fake_borrow_temps, source_info)
622
613
} else {
623
- base_place = base_place. expect_upvars_resolved ( self ) ;
624
614
self . add_fake_borrows_of_base (
625
- & base_place,
615
+ base_place. to_place ( self ) ,
626
616
block,
627
617
fake_borrow_temps,
628
618
expr_span,
@@ -636,7 +626,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
636
626
fn bounds_check (
637
627
& mut self ,
638
628
block : BasicBlock ,
639
- slice : PlaceBuilder < ' tcx > ,
629
+ slice : & PlaceBuilder < ' tcx > ,
640
630
index : Local ,
641
631
expr_span : Span ,
642
632
source_info : SourceInfo ,
@@ -648,7 +638,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
648
638
let lt = self . temp ( bool_ty, expr_span) ;
649
639
650
640
// len = len(slice)
651
- self . cfg . push_assign ( block, source_info, len, Rvalue :: Len ( slice. into_place ( self ) ) ) ;
641
+ self . cfg . push_assign ( block, source_info, len, Rvalue :: Len ( slice. to_place ( self ) ) ) ;
652
642
// lt = idx < len
653
643
self . cfg . push_assign (
654
644
block,
@@ -666,19 +656,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
666
656
667
657
fn add_fake_borrows_of_base (
668
658
& mut self ,
669
- base_place : & PlaceBuilder < ' tcx > ,
659
+ base_place : Place < ' tcx > ,
670
660
block : BasicBlock ,
671
661
fake_borrow_temps : & mut Vec < Local > ,
672
662
expr_span : Span ,
673
663
source_info : SourceInfo ,
674
664
) {
675
665
let tcx = self . tcx ;
676
- let local = match base_place. base {
677
- PlaceBase :: Local ( local) => local,
678
- PlaceBase :: Upvar { .. } => bug ! ( "Expected PlacseBase::Local found Upvar" ) ,
679
- } ;
680
666
681
- let place_ty = Place :: ty_from ( local , & base_place. projection , & self . local_decls , tcx) ;
667
+ let place_ty = base_place. ty ( & self . local_decls , tcx) ;
682
668
if let ty:: Slice ( _) = place_ty. ty . kind ( ) {
683
669
// We need to create fake borrows to ensure that the bounds
684
670
// check that we just did stays valid. Since we can't assign to
@@ -688,7 +674,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
688
674
match elem {
689
675
ProjectionElem :: Deref => {
690
676
let fake_borrow_deref_ty = Place :: ty_from (
691
- local,
677
+ base_place . local ,
692
678
& base_place. projection [ ..idx] ,
693
679
& self . local_decls ,
694
680
tcx,
@@ -706,14 +692,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
706
692
Rvalue :: Ref (
707
693
tcx. lifetimes . re_erased ,
708
694
BorrowKind :: Shallow ,
709
- Place { local, projection } ,
695
+ Place { local : base_place . local , projection } ,
710
696
) ,
711
697
) ;
712
698
fake_borrow_temps. push ( fake_borrow_temp) ;
713
699
}
714
700
ProjectionElem :: Index ( _) => {
715
701
let index_ty = Place :: ty_from (
716
- local,
702
+ base_place . local ,
717
703
& base_place. projection [ ..idx] ,
718
704
& self . local_decls ,
719
705
tcx,
0 commit comments