Skip to content

Commit d406d89

Browse files
authored
Rollup merge of #62096 - spastorino:impl-place-from, r=oli-obk,Centril
Implement From<Local> for Place and PlaceBase r? @oli-obk More tiny bits of Place 2.0 moved into master
2 parents abc7423 + 099f9e4 commit d406d89

32 files changed

+114
-105
lines changed

src/librustc/mir/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,18 @@ impl<'tcx> Place<'tcx> {
20962096
}
20972097
}
20982098

2099+
impl From<Local> for Place<'_> {
2100+
fn from(local: Local) -> Self {
2101+
Place::Base(local.into())
2102+
}
2103+
}
2104+
2105+
impl From<Local> for PlaceBase<'_> {
2106+
fn from(local: Local) -> Self {
2107+
PlaceBase::Local(local)
2108+
}
2109+
}
2110+
20992111
/// A linked list of projections running up the stack; begins with the
21002112
/// innermost projection and extends to the outermost (e.g., `a.b.c`
21012113
/// would have the place `b` with a "next" pointer to `b.c`).

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
470470
}
471471
mir::ProjectionElem::Index(index) => {
472472
let index = &mir::Operand::Copy(
473-
mir::Place::Base(mir::PlaceBase::Local(index))
473+
mir::Place::from(index)
474474
);
475475
let index = self.codegen_operand(bx, index);
476476
let llindex = index.immediate();

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
627627
def_id, is_generator, places
628628
);
629629
if let Some((args_span, var_span)) = self.closure_span(
630-
*def_id, &Place::Base(PlaceBase::Local(target)), places
630+
*def_id, &Place::from(target), places
631631
) {
632632
return ClosureUse {
633633
is_generator,

src/librustc_mir/borrow_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
620620
StatementKind::StorageDead(local) => {
621621
self.access_place(
622622
location,
623-
(&Place::Base(PlaceBase::Local(local)), span),
623+
(&Place::from(local), span),
624624
(Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
625625
LocalMutationIsAllowed::Yes,
626626
flow_state,

src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
252252
Some(Cause::LiveVar(local, location)) => {
253253
let span = body.source_info(location).span;
254254
let spans = self
255-
.move_spans(&Place::Base(PlaceBase::Local(local)), location)
255+
.move_spans(&Place::from(local), location)
256256
.or_else(|| self.borrow_spans(span, location));
257257

258258
let borrow_location = location;

src/librustc_mir/borrow_check/nll/invalidation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::borrow_check::path_utils::*;
1111
use crate::dataflow::indexes::BorrowIndex;
1212
use rustc::ty::TyCtxt;
1313
use rustc::mir::visit::Visitor;
14-
use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase, Rvalue};
14+
use rustc::mir::{BasicBlock, Location, Body, Place, Rvalue};
1515
use rustc::mir::{Statement, StatementKind};
1616
use rustc::mir::TerminatorKind;
1717
use rustc::mir::{Operand, BorrowKind};
@@ -124,7 +124,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
124124
StatementKind::StorageDead(local) => {
125125
self.access_place(
126126
location,
127-
&Place::Base(PlaceBase::Local(local)),
127+
&Place::from(local),
128128
(Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
129129
LocalMutationIsAllowed::Yes,
130130
);

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
632632
)
633633
}
634634
ProjectionElem::Index(i) => {
635-
let index_ty = Place::Base(PlaceBase::Local(i)).ty(self.body, tcx).ty;
635+
let index_ty = Place::from(i).ty(self.body, tcx).ty;
636636
if index_ty != tcx.types.usize {
637637
PlaceTy::from_ty(
638638
span_mirbug_and_err!(self, i, "index by non-usize {:?}", i),

src/librustc_mir/build/expr/as_operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7474
}
7575
Category::Place | Category::Rvalue(..) => {
7676
let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut));
77-
block.and(Operand::Move(Place::Base(PlaceBase::Local(operand))))
77+
block.and(Operand::Move(Place::from(operand)))
7878
}
7979
}
8080
}

src/librustc_mir/build/expr/as_place.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9898
&lt,
9999
Rvalue::BinaryOp(
100100
BinOp::Lt,
101-
Operand::Copy(Place::Base(PlaceBase::Local(idx))),
101+
Operand::Copy(Place::from(idx)),
102102
Operand::Copy(len.clone()),
103103
),
104104
);
105105

106106
let msg = BoundsCheck {
107107
len: Operand::Move(len),
108-
index: Operand::Copy(Place::Base(PlaceBase::Local(idx))),
108+
index: Operand::Copy(Place::from(idx)),
109109
};
110110
let success = this.assert(block, Operand::Move(lt), true, msg, expr_span);
111111
success.and(slice.index(idx))
112112
}
113-
ExprKind::SelfRef => block.and(Place::Base(PlaceBase::Local(Local::new(1)))),
113+
ExprKind::SelfRef => block.and(Place::from(Local::new(1))),
114114
ExprKind::VarRef { id } => {
115115
let place = if this.is_bound_var_in_guard(id) {
116116
let index = this.var_local_id(id, RefWithinGuard);
117-
Place::Base(PlaceBase::Local(index)).deref()
117+
Place::from(index).deref()
118118
} else {
119119
let index = this.var_local_id(id, OutsideGuard);
120-
Place::Base(PlaceBase::Local(index))
120+
Place::from(index)
121121
};
122122
block.and(place)
123123
}
@@ -168,14 +168,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
168168
Statement {
169169
source_info,
170170
kind: StatementKind::AscribeUserType(
171-
Place::Base(PlaceBase::Local(temp.clone())),
171+
Place::from(temp.clone()),
172172
Variance::Invariant,
173173
box UserTypeProjection { base: annotation_index, projs: vec![], },
174174
),
175175
},
176176
);
177177
}
178-
block.and(Place::Base(PlaceBase::Local(temp)))
178+
block.and(Place::from(temp))
179179
}
180180

181181
ExprKind::Array { .. }
@@ -211,7 +211,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
211211
});
212212
let temp =
213213
unpack!(block = this.as_temp(block, expr.temp_lifetime, expr, mutability));
214-
block.and(Place::Base(PlaceBase::Local(temp)))
214+
block.and(Place::from(temp))
215215
}
216216
}
217217
}

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
127127
this.schedule_drop_storage_and_value(
128128
expr_span,
129129
scope,
130-
&Place::Base(PlaceBase::Local(result)),
130+
&Place::from(result),
131131
value.ty,
132132
);
133133
}
134134

135135
// malloc some memory of suitable type (thus far, uninitialized):
136136
let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty);
137137
this.cfg
138-
.push_assign(block, source_info, &Place::Base(PlaceBase::Local(result)), box_);
138+
.push_assign(block, source_info, &Place::from(result), box_);
139139

140140
// initialize the box contents:
141141
unpack!(
142142
block = this.into(
143-
&Place::Base(PlaceBase::Local(result)).deref(),
143+
&Place::from(result).deref(),
144144
block, value
145145
)
146146
);
147-
block.and(Rvalue::Use(Operand::Move(Place::Base(PlaceBase::Local(result)))))
147+
block.and(Rvalue::Use(Operand::Move(Place::from(result))))
148148
}
149149
ExprKind::Cast { source } => {
150150
let source = unpack!(block = this.as_operand(block, scope, source));
@@ -548,7 +548,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
548548
this.cfg.push_assign(
549549
block,
550550
source_info,
551-
&Place::Base(PlaceBase::Local(temp)),
551+
&Place::from(temp),
552552
Rvalue::Ref(this.hir.tcx().lifetimes.re_erased, borrow_kind, arg_place),
553553
);
554554

@@ -559,12 +559,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
559559
this.schedule_drop_storage_and_value(
560560
upvar_span,
561561
temp_lifetime,
562-
&Place::Base(PlaceBase::Local(temp)),
562+
&Place::from(temp),
563563
upvar_ty,
564564
);
565565
}
566566

567-
block.and(Operand::Move(Place::Base(PlaceBase::Local(temp))))
567+
block.and(Operand::Move(Place::from(temp)))
568568
}
569569

570570
// Helper to get a `-1` value of the appropriate type

0 commit comments

Comments
 (0)