Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement From<Local> for Place and PlaceBase #62096

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2096,6 +2096,18 @@ impl<'tcx> Place<'tcx> {
}
}

impl From<Local> for Place<'_> {
fn from(local: Local) -> Self {
Place::Base(local.into())
}
}

impl From<Local> for PlaceBase<'_> {
fn from(local: Local) -> Self {
PlaceBase::Local(local)
}
}

/// A linked list of projections running up the stack; begins with the
/// innermost projection and extends to the outermost (e.g., `a.b.c`
/// would have the place `b` with a "next" pointer to `b.c`).
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
mir::ProjectionElem::Index(index) => {
let index = &mir::Operand::Copy(
mir::Place::Base(mir::PlaceBase::Local(index))
mir::Place::from(index)
);
let index = self.codegen_operand(bx, index);
let llindex = index.immediate();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
def_id, is_generator, places
);
if let Some((args_span, var_span)) = self.closure_span(
*def_id, &Place::Base(PlaceBase::Local(target)), places
*def_id, &Place::from(target), places
) {
return ClosureUse {
is_generator,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
StatementKind::StorageDead(local) => {
self.access_place(
location,
(&Place::Base(PlaceBase::Local(local)), span),
(&Place::from(local), span),
(Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
LocalMutationIsAllowed::Yes,
flow_state,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Some(Cause::LiveVar(local, location)) => {
let span = body.source_info(location).span;
let spans = self
.move_spans(&Place::Base(PlaceBase::Local(local)), location)
.move_spans(&Place::from(local), location)
.or_else(|| self.borrow_spans(span, location));

let borrow_location = location;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/nll/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::borrow_check::path_utils::*;
use crate::dataflow::indexes::BorrowIndex;
use rustc::ty::TyCtxt;
use rustc::mir::visit::Visitor;
use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase, Rvalue};
use rustc::mir::{BasicBlock, Location, Body, Place, Rvalue};
use rustc::mir::{Statement, StatementKind};
use rustc::mir::TerminatorKind;
use rustc::mir::{Operand, BorrowKind};
Expand Down Expand Up @@ -124,7 +124,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
StatementKind::StorageDead(local) => {
self.access_place(
location,
&Place::Base(PlaceBase::Local(local)),
&Place::from(local),
(Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
LocalMutationIsAllowed::Yes,
);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
)
}
ProjectionElem::Index(i) => {
let index_ty = Place::Base(PlaceBase::Local(i)).ty(self.body, tcx).ty;
let index_ty = Place::from(i).ty(self.body, tcx).ty;
if index_ty != tcx.types.usize {
PlaceTy::from_ty(
span_mirbug_and_err!(self, i, "index by non-usize {:?}", i),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/as_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
Category::Place | Category::Rvalue(..) => {
let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut));
block.and(Operand::Move(Place::Base(PlaceBase::Local(operand))))
block.and(Operand::Move(Place::from(operand)))
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_mir/build/expr/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&lt,
Rvalue::BinaryOp(
BinOp::Lt,
Operand::Copy(Place::Base(PlaceBase::Local(idx))),
Operand::Copy(Place::from(idx)),
Operand::Copy(len.clone()),
),
);

let msg = BoundsCheck {
len: Operand::Move(len),
index: Operand::Copy(Place::Base(PlaceBase::Local(idx))),
index: Operand::Copy(Place::from(idx)),
};
let success = this.assert(block, Operand::Move(lt), true, msg, expr_span);
success.and(slice.index(idx))
}
ExprKind::SelfRef => block.and(Place::Base(PlaceBase::Local(Local::new(1)))),
ExprKind::SelfRef => block.and(Place::from(Local::new(1))),
ExprKind::VarRef { id } => {
let place = if this.is_bound_var_in_guard(id) {
let index = this.var_local_id(id, RefWithinGuard);
Place::Base(PlaceBase::Local(index)).deref()
Place::from(index).deref()
} else {
let index = this.var_local_id(id, OutsideGuard);
Place::Base(PlaceBase::Local(index))
Place::from(index)
};
block.and(place)
}
Expand Down Expand Up @@ -168,14 +168,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Statement {
source_info,
kind: StatementKind::AscribeUserType(
Place::Base(PlaceBase::Local(temp.clone())),
Place::from(temp.clone()),
Variance::Invariant,
box UserTypeProjection { base: annotation_index, projs: vec![], },
),
},
);
}
block.and(Place::Base(PlaceBase::Local(temp)))
block.and(Place::from(temp))
}

ExprKind::Array { .. }
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
});
let temp =
unpack!(block = this.as_temp(block, expr.temp_lifetime, expr, mutability));
block.and(Place::Base(PlaceBase::Local(temp)))
block.and(Place::from(temp))
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_mir/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.schedule_drop_storage_and_value(
expr_span,
scope,
&Place::Base(PlaceBase::Local(result)),
&Place::from(result),
value.ty,
);
}

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

// initialize the box contents:
unpack!(
block = this.into(
&Place::Base(PlaceBase::Local(result)).deref(),
&Place::from(result).deref(),
block, value
)
);
block.and(Rvalue::Use(Operand::Move(Place::Base(PlaceBase::Local(result)))))
block.and(Rvalue::Use(Operand::Move(Place::from(result))))
}
ExprKind::Cast { source } => {
let source = unpack!(block = this.as_operand(block, scope, source));
Expand Down Expand Up @@ -548,7 +548,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.cfg.push_assign(
block,
source_info,
&Place::Base(PlaceBase::Local(temp)),
&Place::from(temp),
Rvalue::Ref(this.hir.tcx().lifetimes.re_erased, borrow_kind, arg_place),
);

Expand All @@ -559,12 +559,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.schedule_drop_storage_and_value(
upvar_span,
temp_lifetime,
&Place::Base(PlaceBase::Local(temp)),
&Place::from(temp),
upvar_ty,
);
}

block.and(Operand::Move(Place::Base(PlaceBase::Local(temp))))
block.and(Operand::Move(Place::from(temp)))
}

// Helper to get a `-1` value of the appropriate type
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/as_temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
this.local_decls.push(local_decl)
};
let temp_place = &Place::Base(PlaceBase::Local(temp));
let temp_place = &Place::from(temp);

if !expr_ty.is_never() {
this.cfg.push(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
is_user_variable: None,
is_block_tail: None,
});
let ptr_temp = Place::Base(PlaceBase::Local(ptr_temp));
let ptr_temp = Place::from(ptr_temp);
let block = unpack!(this.into(&ptr_temp, block, ptr));
this.into(&ptr_temp.deref(), block, val)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}
let temp = this.local_decls.push(local_decl);
let place = Place::Base(PlaceBase::Local(temp));
let place = Place::from(temp);
debug!("created temp {:?} for expr {:?} in block_context: {:?}",
temp, expr, this.block_context);
place
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_mir/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
kind: StatementKind::StorageLive(local_id),
},
);
let place = Place::Base(PlaceBase::Local(local_id));
let place = Place::from(local_id);
let var_ty = self.local_decls[local_id].ty;
let region_scope = self.hir.region_scope_tree.var_scope(var.local_id);
self.schedule_drop(span, region_scope, &place, var_ty, DropKind::Storage);
Expand All @@ -545,7 +545,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.schedule_drop(
span,
region_scope,
&Place::Base(PlaceBase::Local(local_id)),
&Place::from(local_id),
var_ty,
DropKind::Value,
);
Expand Down Expand Up @@ -1478,7 +1478,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.cfg.push_assign(
block,
scrutinee_source_info,
&Place::Base(PlaceBase::Local(temp)),
&Place::from(temp),
borrow,
);
}
Expand All @@ -1502,7 +1502,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
source_info: guard_end,
kind: StatementKind::FakeRead(
FakeReadCause::ForMatchGuard,
Place::Base(PlaceBase::Local(temp)),
Place::from(temp),
),
});
}
Expand Down Expand Up @@ -1575,7 +1575,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// place they refer to can't be modified by the guard.
for binding in by_value_bindings.clone() {
let local_id = self.var_local_id(binding.var_id, RefWithinGuard);
let place = Place::Base(PlaceBase::Local(local_id));
let place = Place::from(local_id);
self.cfg.push(
block,
Statement {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// call `schedule_drop` once the temporary is initialized.
pub fn temp(&mut self, ty: Ty<'tcx>, span: Span) -> Place<'tcx> {
let temp = self.local_decls.push(LocalDecl::new_temp(ty, span));
let place = Place::Base(PlaceBase::Local(temp));
let place = Place::from(temp);
debug!("temp: created temp {:?} with type {:?}",
place, self.local_decls[temp].ty);
place
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
for (index, arg_info) in arguments.iter().enumerate() {
// Function arguments always get the first Local indices after the return place
let local = Local::new(index + 1);
let place = Place::Base(PlaceBase::Local(local));
let place = Place::from(local);
let &ArgInfo(ty, opt_ty_info, pattern, ref self_binding) = arg_info;

// Make sure we drop (parts of) the argument even when not matched on.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/drop_flag_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub(crate) fn drop_flag_effects_for_function_entry<'tcx, F>(
{
let move_data = &ctxt.move_data;
for arg in body.args_iter() {
let place = mir::Place::Base(mir::PlaceBase::Local(arg));
let place = mir::Place::from(arg);
let lookup_result = move_data.rev_lookup.find(&place);
on_lookup_result_bits(tcx, body, move_data,
lookup_result,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'tcx> {
mir::StatementKind::StorageDead(local) => {
// Make sure there are no remaining borrows for locals that
// are gone out of scope.
self.kill_borrows_on_place(trans, &Place::Base(PlaceBase::Local(local)));
self.kill_borrows_on_place(trans, &Place::from(local));
}

mir::StatementKind::InlineAsm(ref asm) => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/dataflow/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
moves: IndexVec::new(),
loc_map: LocationMap::new(body),
rev_lookup: MovePathLookup {
locals: body.local_decls.indices().map(PlaceBase::Local).map(|v| {
locals: body.local_decls.indices().map(|i| {
Self::new_move_path(
&mut move_paths,
&mut path_map,
&mut init_path_map,
None,
Place::Base(v),
Place::from(i),
)
}).collect(),
projections: Default::default(),
Expand Down Expand Up @@ -289,7 +289,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
}
StatementKind::StorageLive(_) => {}
StatementKind::StorageDead(local) => {
self.gather_move(&Place::Base(PlaceBase::Local(local)));
self.gather_move(&Place::from(local));
}
StatementKind::SetDiscriminant{ .. } => {
span_bug!(stmt.source_info.span,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
let mut locals_iter = body.args_iter();
while let Some(local) = locals_iter.next() {
let dest = self.eval_place(
&mir::Place::Base(mir::PlaceBase::Local(local))
&mir::Place::from(local)
)?;
if Some(local) == body.spread_arg {
// Must be a tuple
Expand Down
Loading