Skip to content

Commit 105abe3

Browse files
committed
Replace into_place with to_place
1 parent be5b777 commit 105abe3

File tree

4 files changed

+20
-34
lines changed

4 files changed

+20
-34
lines changed

compiler/rustc_mir_build/src/build/expr/as_place.rs

+16-30
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(crate) enum PlaceBase {
6565

6666
/// `PlaceBuilder` is used to create places during MIR construction. It allows you to "build up" a
6767
/// 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.
6969
///
7070
/// This is used internally when building a place for an expression like `a.b.c`. The fields `b`
7171
/// 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>(
254254
}
255255

256256
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()
268259
}
269260

270261
/// Creates a `Place` or returns `None` if an upvar cannot be resolved
@@ -363,7 +354,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
363354
expr: &Expr<'tcx>,
364355
) -> BlockAnd<Place<'tcx>> {
365356
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))
367358
}
368359

369360
/// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -387,7 +378,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
387378
expr: &Expr<'tcx>,
388379
) -> BlockAnd<Place<'tcx>> {
389380
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))
391382
}
392383

393384
/// This is used when constructing a compound `Place`, so that we can avoid creating
@@ -482,7 +473,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
482473
inferred_ty: expr.ty,
483474
});
484475

485-
let place = place_builder.clone().into_place(this);
476+
let place = place_builder.to_place(this);
486477
this.cfg.push(
487478
block,
488479
Statement {
@@ -607,22 +598,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
607598
let is_outermost_index = fake_borrow_temps.is_none();
608599
let fake_borrow_temps = fake_borrow_temps.unwrap_or(base_fake_borrow_temps);
609600

610-
let mut base_place =
601+
let base_place =
611602
unpack!(block = self.expr_as_place(block, base, mutability, Some(fake_borrow_temps),));
612603

613604
// Making this a *fresh* temporary means we do not have to worry about
614605
// the index changing later: Nothing will ever change this temporary.
615606
// The "retagging" transformation (for Stacked Borrows) relies on this.
616607
let idx = unpack!(block = self.as_temp(block, temp_lifetime, index, Mutability::Not,));
617608

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);
619610

620611
if is_outermost_index {
621612
self.read_fake_borrows(block, fake_borrow_temps, source_info)
622613
} else {
623-
base_place = base_place.expect_upvars_resolved(self);
624614
self.add_fake_borrows_of_base(
625-
&base_place,
615+
base_place.to_place(self),
626616
block,
627617
fake_borrow_temps,
628618
expr_span,
@@ -636,7 +626,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
636626
fn bounds_check(
637627
&mut self,
638628
block: BasicBlock,
639-
slice: PlaceBuilder<'tcx>,
629+
slice: &PlaceBuilder<'tcx>,
640630
index: Local,
641631
expr_span: Span,
642632
source_info: SourceInfo,
@@ -648,7 +638,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
648638
let lt = self.temp(bool_ty, expr_span);
649639

650640
// 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)));
652642
// lt = idx < len
653643
self.cfg.push_assign(
654644
block,
@@ -666,19 +656,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
666656

667657
fn add_fake_borrows_of_base(
668658
&mut self,
669-
base_place: &PlaceBuilder<'tcx>,
659+
base_place: Place<'tcx>,
670660
block: BasicBlock,
671661
fake_borrow_temps: &mut Vec<Local>,
672662
expr_span: Span,
673663
source_info: SourceInfo,
674664
) {
675665
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-
};
680666

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);
682668
if let ty::Slice(_) = place_ty.ty.kind() {
683669
// We need to create fake borrows to ensure that the bounds
684670
// check that we just did stays valid. Since we can't assign to
@@ -688,7 +674,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
688674
match elem {
689675
ProjectionElem::Deref => {
690676
let fake_borrow_deref_ty = Place::ty_from(
691-
local,
677+
base_place.local,
692678
&base_place.projection[..idx],
693679
&self.local_decls,
694680
tcx,
@@ -706,14 +692,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
706692
Rvalue::Ref(
707693
tcx.lifetimes.re_erased,
708694
BorrowKind::Shallow,
709-
Place { local, projection },
695+
Place { local: base_place.local, projection },
710696
),
711697
);
712698
fake_borrow_temps.push(fake_borrow_temp);
713699
}
714700
ProjectionElem::Index(_) => {
715701
let index_ty = Place::ty_from(
716-
local,
702+
base_place.local,
717703
&base_place.projection[..idx],
718704
&self.local_decls,
719705
tcx,

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
660660
// by the parent itself. The mutability of the current capture
661661
// is same as that of the capture in the parent closure.
662662
PlaceBase::Upvar { .. } => {
663-
let enclosing_upvars_resolved = arg_place_builder.clone().into_place(this);
663+
let enclosing_upvars_resolved = arg_place_builder.to_place(this);
664664

665665
match enclosing_upvars_resolved.as_ref() {
666666
PlaceRef {
@@ -697,7 +697,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
697697
Mutability::Mut => BorrowKind::Mut { allow_two_phase_borrow: false },
698698
};
699699

700-
let arg_place = arg_place_builder.into_place(this);
700+
let arg_place = arg_place_builder.to_place(this);
701701

702702
this.cfg.push_assign(
703703
block,

compiler/rustc_mir_build/src/build/expr/into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
365365
None => {
366366
let place_builder = place_builder.clone();
367367
this.consume_by_copy_or_move(
368-
place_builder.field(n, *ty).into_place(this),
368+
place_builder.field(n, *ty).to_place(this),
369369
)
370370
}
371371
})

compiler/rustc_mir_build/src/build/matches/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
154154
test: &Test<'tcx>,
155155
make_target_blocks: impl FnOnce(&mut Self) -> Vec<BasicBlock>,
156156
) {
157-
let place = place_builder.into_place(self);
157+
let place = place_builder.to_place(self);
158158
let place_ty = place.ty(&self.local_decls, self.tcx);
159159
debug!(?place, ?place_ty,);
160160

0 commit comments

Comments
 (0)