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

+12
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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

+8-8
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

+7-7
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

src/librustc_mir/build/expr/as_temp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6464
}
6565
this.local_decls.push(local_decl)
6666
};
67-
let temp_place = &Place::Base(PlaceBase::Local(temp));
67+
let temp_place = &Place::from(temp);
6868

6969
if !expr_ty.is_never() {
7070
this.cfg.push(

src/librustc_mir/build/expr/into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
258258
is_user_variable: None,
259259
is_block_tail: None,
260260
});
261-
let ptr_temp = Place::Base(PlaceBase::Local(ptr_temp));
261+
let ptr_temp = Place::from(ptr_temp);
262262
let block = unpack!(this.into(&ptr_temp, block, ptr));
263263
this.into(&ptr_temp.deref(), block, val)
264264
} else {

src/librustc_mir/build/expr/stmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
235235
}
236236
}
237237
let temp = this.local_decls.push(local_decl);
238-
let place = Place::Base(PlaceBase::Local(temp));
238+
let place = Place::from(temp);
239239
debug!("created temp {:?} for expr {:?} in block_context: {:?}",
240240
temp, expr, this.block_context);
241241
place

src/librustc_mir/build/matches/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
531531
kind: StatementKind::StorageLive(local_id),
532532
},
533533
);
534-
let place = Place::Base(PlaceBase::Local(local_id));
534+
let place = Place::from(local_id);
535535
let var_ty = self.local_decls[local_id].ty;
536536
let region_scope = self.hir.region_scope_tree.var_scope(var.local_id);
537537
self.schedule_drop(span, region_scope, &place, var_ty, DropKind::Storage);
@@ -545,7 +545,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
545545
self.schedule_drop(
546546
span,
547547
region_scope,
548-
&Place::Base(PlaceBase::Local(local_id)),
548+
&Place::from(local_id),
549549
var_ty,
550550
DropKind::Value,
551551
);
@@ -1478,7 +1478,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14781478
self.cfg.push_assign(
14791479
block,
14801480
scrutinee_source_info,
1481-
&Place::Base(PlaceBase::Local(temp)),
1481+
&Place::from(temp),
14821482
borrow,
14831483
);
14841484
}
@@ -1502,7 +1502,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15021502
source_info: guard_end,
15031503
kind: StatementKind::FakeRead(
15041504
FakeReadCause::ForMatchGuard,
1505-
Place::Base(PlaceBase::Local(temp)),
1505+
Place::from(temp),
15061506
),
15071507
});
15081508
}
@@ -1575,7 +1575,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15751575
// place they refer to can't be modified by the guard.
15761576
for binding in by_value_bindings.clone() {
15771577
let local_id = self.var_local_id(binding.var_id, RefWithinGuard);
1578-
let place = Place::Base(PlaceBase::Local(local_id));
1578+
let place = Place::from(local_id);
15791579
self.cfg.push(
15801580
block,
15811581
Statement {

src/librustc_mir/build/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1616
/// call `schedule_drop` once the temporary is initialized.
1717
pub fn temp(&mut self, ty: Ty<'tcx>, span: Span) -> Place<'tcx> {
1818
let temp = self.local_decls.push(LocalDecl::new_temp(ty, span));
19-
let place = Place::Base(PlaceBase::Local(temp));
19+
let place = Place::from(temp);
2020
debug!("temp: created temp {:?} with type {:?}",
2121
place, self.local_decls[temp].ty);
2222
place

src/librustc_mir/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
808808
for (index, arg_info) in arguments.iter().enumerate() {
809809
// Function arguments always get the first Local indices after the return place
810810
let local = Local::new(index + 1);
811-
let place = Place::Base(PlaceBase::Local(local));
811+
let place = Place::from(local);
812812
let &ArgInfo(ty, opt_ty_info, pattern, ref self_binding) = arg_info;
813813

814814
// Make sure we drop (parts of) the argument even when not matched on.

src/librustc_mir/dataflow/drop_flag_effects.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub(crate) fn drop_flag_effects_for_function_entry<'tcx, F>(
170170
{
171171
let move_data = &ctxt.move_data;
172172
for arg in body.args_iter() {
173-
let place = mir::Place::Base(mir::PlaceBase::Local(arg));
173+
let place = mir::Place::from(arg);
174174
let lookup_result = move_data.rev_lookup.find(&place);
175175
on_lookup_result_bits(tcx, body, move_data,
176176
lookup_result,

src/librustc_mir/dataflow/impls/borrows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'tcx> {
288288
mir::StatementKind::StorageDead(local) => {
289289
// Make sure there are no remaining borrows for locals that
290290
// are gone out of scope.
291-
self.kill_borrows_on_place(trans, &Place::Base(PlaceBase::Local(local)));
291+
self.kill_borrows_on_place(trans, &Place::from(local));
292292
}
293293

294294
mir::StatementKind::InlineAsm(ref asm) => {

src/librustc_mir/dataflow/move_paths/builder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
3333
moves: IndexVec::new(),
3434
loc_map: LocationMap::new(body),
3535
rev_lookup: MovePathLookup {
36-
locals: body.local_decls.indices().map(PlaceBase::Local).map(|v| {
36+
locals: body.local_decls.indices().map(|i| {
3737
Self::new_move_path(
3838
&mut move_paths,
3939
&mut path_map,
4040
&mut init_path_map,
4141
None,
42-
Place::Base(v),
42+
Place::from(i),
4343
)
4444
}).collect(),
4545
projections: Default::default(),
@@ -289,7 +289,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
289289
}
290290
StatementKind::StorageLive(_) => {}
291291
StatementKind::StorageDead(local) => {
292-
self.gather_move(&Place::Base(PlaceBase::Local(local)));
292+
self.gather_move(&Place::from(local));
293293
}
294294
StatementKind::SetDiscriminant{ .. } => {
295295
span_bug!(stmt.source_info.span,

src/librustc_mir/interpret/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
355355
let mut locals_iter = body.args_iter();
356356
while let Some(local) = locals_iter.next() {
357357
let dest = self.eval_place(
358-
&mir::Place::Base(mir::PlaceBase::Local(local))
358+
&mir::Place::from(local)
359359
)?;
360360
if Some(local) == body.spread_arg {
361361
// Must be a tuple

0 commit comments

Comments
 (0)