Auto merge of #68512 - spastorino:local-is-copy, r=oli-obk

Local is copy

r? @oli-obk
This commit is contained in:
bors 2020-01-29 04:36:50 +00:00
commit 343432a74d
31 changed files with 134 additions and 130 deletions

View File

@ -1773,7 +1773,7 @@ rustc_index::newtype_index! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PlaceRef<'a, 'tcx> {
pub local: &'a Local,
pub local: Local,
pub projection: &'a [PlaceElem<'tcx>],
}
@ -1797,8 +1797,8 @@ impl<'tcx> Place<'tcx> {
// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
pub fn local_or_deref_local(&self) -> Option<Local> {
match self.as_ref() {
PlaceRef { local, projection: &[] }
| PlaceRef { local, projection: &[ProjectionElem::Deref] } => Some(*local),
PlaceRef { local, projection: [] }
| PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),
_ => None,
}
}
@ -1810,7 +1810,7 @@ impl<'tcx> Place<'tcx> {
}
pub fn as_ref(&self) -> PlaceRef<'_, 'tcx> {
PlaceRef { local: &self.local, projection: &self.projection }
PlaceRef { local: self.local, projection: &self.projection }
}
}
@ -1826,9 +1826,9 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
//
// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
pub fn local_or_deref_local(&self) -> Option<Local> {
match self {
match *self {
PlaceRef { local, projection: [] }
| PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(**local),
| PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),
_ => None,
}
}
@ -1836,8 +1836,8 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
/// If this place represents a local variable like `_X` with no
/// projections, return `Some(_X)`.
pub fn as_local(&self) -> Option<Local> {
match self {
PlaceRef { local, projection: [] } => Some(**local),
match *self {
PlaceRef { local, projection: [] } => Some(local),
_ => None,
}
}

View File

@ -114,7 +114,7 @@ impl<'tcx> PlaceTy<'tcx> {
impl<'tcx> Place<'tcx> {
pub fn ty_from<D>(
local: &Local,
local: Local,
projection: &[PlaceElem<'tcx>],
local_decls: &D,
tcx: TyCtxt<'tcx>,
@ -124,7 +124,7 @@ impl<'tcx> Place<'tcx> {
{
projection
.iter()
.fold(PlaceTy::from_ty(local_decls.local_decls()[*local].ty), |place_ty, elem| {
.fold(PlaceTy::from_ty(local_decls.local_decls()[local].ty), |place_ty, elem| {
place_ty.projection_ty(tcx, elem)
})
}
@ -133,7 +133,7 @@ impl<'tcx> Place<'tcx> {
where
D: HasLocalDecls<'tcx>,
{
Place::ty_from(&self.local, &self.projection, local_decls, tcx)
Place::ty_from(self.local, &self.projection, local_decls, tcx)
}
}

View File

@ -134,7 +134,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
// ZSTs don't require any actual memory access.
let elem_ty = base_ty.projection_ty(cx.tcx(), elem).ty;
let elem_ty = self.fx.monomorphize(&elem_ty);
let span = self.fx.mir.local_decls[*place_ref.local].source_info.span;
let span = self.fx.mir.local_decls[place_ref.local].source_info.span;
if cx.spanned_layout_of(elem_ty, span).is_zst() {
return;
}
@ -174,7 +174,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
// We use `NonUseContext::VarDebugInfo` for the base,
// which might not force the base local to memory,
// so we have to do it manually.
self.visit_local(place_ref.local, context, location);
self.visit_local(&place_ref.local, context, location);
}
}
@ -212,8 +212,8 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
};
}
self.visit_place_base(place_ref.local, context, location);
self.visit_projection(place_ref.local, place_ref.projection, context, location);
self.visit_place_base(&place_ref.local, context, location);
self.visit_projection(&place_ref.local, place_ref.projection, context, location);
}
}
}

View File

@ -264,7 +264,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
PassMode::Direct(_) | PassMode::Pair(..) => {
let op = self.codegen_consume(&mut bx, &mir::Place::return_place().as_ref());
let op = self.codegen_consume(&mut bx, mir::Place::return_place().as_ref());
if let Ref(llval, _, align) = op.val {
bx.load(llval, align)
} else {
@ -319,7 +319,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
return;
}
let place = self.codegen_place(&mut bx, &location.as_ref());
let place = self.codegen_place(&mut bx, location.as_ref());
let (args1, args2);
let mut args = if let Some(llextra) = place.llextra {
args2 = [place.llval, llextra];
@ -1111,7 +1111,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
} else {
self.codegen_place(
bx,
&mir::PlaceRef { local: &dest.local, projection: &dest.projection },
mir::PlaceRef { local: dest.local, projection: &dest.projection },
)
};
if fn_ret.is_indirect() {
@ -1137,7 +1137,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place),
LocalRef::UnsizedPlace(_) => bug!("transmute must not involve unsized locals"),
LocalRef::Operand(None) => {
let dst_layout = bx.layout_of(self.monomorphized_place_ty(&dst.as_ref()));
let dst_layout = bx.layout_of(self.monomorphized_place_ty(dst.as_ref()));
assert!(!dst_layout.ty.has_erasable_regions());
let place = PlaceRef::alloca(bx, dst_layout);
place.storage_live(bx);
@ -1151,7 +1151,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}
} else {
let dst = self.codegen_place(bx, &dst.as_ref());
let dst = self.codegen_place(bx, dst.as_ref());
self.codegen_transmute_into(bx, src, dst);
}
}

View File

@ -369,11 +369,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
fn maybe_codegen_consume_direct(
&mut self,
bx: &mut Bx,
place_ref: &mir::PlaceRef<'_, 'tcx>,
place_ref: mir::PlaceRef<'_, 'tcx>,
) -> Option<OperandRef<'tcx, Bx::Value>> {
debug!("maybe_codegen_consume_direct(place_ref={:?})", place_ref);
match self.locals[*place_ref.local] {
match self.locals[place_ref.local] {
LocalRef::Operand(Some(mut o)) => {
// Moves out of scalar and scalar pair fields are trivial.
for elem in place_ref.projection.iter() {
@ -413,7 +413,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
pub fn codegen_consume(
&mut self,
bx: &mut Bx,
place_ref: &mir::PlaceRef<'_, 'tcx>,
place_ref: mir::PlaceRef<'_, 'tcx>,
) -> OperandRef<'tcx, Bx::Value> {
debug!("codegen_consume(place_ref={:?})", place_ref);
@ -444,7 +444,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
match *operand {
mir::Operand::Copy(ref place) | mir::Operand::Move(ref place) => {
self.codegen_consume(bx, &place.as_ref())
self.codegen_consume(bx, place.as_ref())
}
mir::Operand::Constant(ref constant) => {

View File

@ -408,14 +408,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
pub fn codegen_place(
&mut self,
bx: &mut Bx,
place_ref: &mir::PlaceRef<'_, 'tcx>,
place_ref: mir::PlaceRef<'_, 'tcx>,
) -> PlaceRef<'tcx, Bx::Value> {
debug!("codegen_place(place_ref={:?})", place_ref);
let cx = self.cx;
let tcx = self.cx.tcx();
let result = match place_ref {
mir::PlaceRef { local, projection: [] } => match self.locals[**local] {
mir::PlaceRef { local, projection: [] } => match self.locals[local] {
LocalRef::Place(place) => {
return place;
}
@ -428,13 +428,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
},
mir::PlaceRef { local, projection: [proj_base @ .., mir::ProjectionElem::Deref] } => {
// Load the pointer from its location.
self.codegen_consume(bx, &mir::PlaceRef { local, projection: proj_base })
self.codegen_consume(bx, mir::PlaceRef { local, projection: proj_base })
.deref(bx.cx())
}
mir::PlaceRef { local, projection: [proj_base @ .., elem] } => {
// FIXME turn this recursion into iteration
let cg_base =
self.codegen_place(bx, &mir::PlaceRef { local, projection: proj_base });
self.codegen_place(bx, mir::PlaceRef { local, projection: proj_base });
match elem {
mir::ProjectionElem::Deref => bug!(),
@ -497,7 +497,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
result
}
pub fn monomorphized_place_ty(&self, place_ref: &mir::PlaceRef<'_, 'tcx>) -> Ty<'tcx> {
pub fn monomorphized_place_ty(&self, place_ref: mir::PlaceRef<'_, 'tcx>) -> Ty<'tcx> {
let tcx = self.cx.tcx();
let place_ty = mir::Place::ty_from(place_ref.local, place_ref.projection, *self.mir, tcx);
self.monomorphize(&place_ty.ty)

View File

@ -467,7 +467,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::Rvalue::Discriminant(ref place) => {
let discr_ty = rvalue.ty(*self.mir, bx.tcx());
let discr = self
.codegen_place(&mut bx, &place.as_ref())
.codegen_place(&mut bx, place.as_ref())
.codegen_get_discr(&mut bx, discr_ty);
(
bx,
@ -541,7 +541,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}
// use common size calculation for non zero-sized types
let cg_value = self.codegen_place(bx, &place.as_ref());
let cg_value = self.codegen_place(bx, place.as_ref());
cg_value.len(bx.cx())
}
@ -552,7 +552,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
place: &mir::Place<'tcx>,
mk_ptr_ty: impl FnOnce(TyCtxt<'tcx>, Ty<'tcx>) -> Ty<'tcx>,
) -> (Bx, OperandRef<'tcx, Bx::Value>) {
let cg_place = self.codegen_place(&mut bx, &place.as_ref());
let cg_place = self.codegen_place(&mut bx, place.as_ref());
let ty = cg_place.layout.ty;

View File

@ -41,12 +41,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}
} else {
let cg_dest = self.codegen_place(&mut bx, &place.as_ref());
let cg_dest = self.codegen_place(&mut bx, place.as_ref());
self.codegen_rvalue(bx, cg_dest, rvalue)
}
}
mir::StatementKind::SetDiscriminant { box ref place, variant_index } => {
self.codegen_place(&mut bx, &place.as_ref())
self.codegen_place(&mut bx, place.as_ref())
.codegen_set_discr(&mut bx, variant_index);
bx
}
@ -70,7 +70,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let outputs = asm
.outputs
.iter()
.map(|output| self.codegen_place(&mut bx, &output.as_ref()))
.map(|output| self.codegen_place(&mut bx, output.as_ref()))
.collect();
let input_vals = asm.inputs.iter().fold(

View File

@ -97,7 +97,7 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> {
));
// If there are borrows on this now dead local, we need to record them as `killed`.
if let StatementKind::StorageDead(ref local) = statement.kind {
if let StatementKind::StorageDead(local) = statement.kind {
record_killed_borrows_for_local(
all_facts,
self.borrow_set,
@ -212,7 +212,7 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
local, location
);
if let Some(borrow_indices) = self.borrow_set.local_map.get(local) {
if let Some(borrow_indices) = self.borrow_set.local_map.get(&local) {
for &borrow_index in borrow_indices {
let places_conflict = places_conflict::places_conflict(
self.infcx.tcx,
@ -239,10 +239,10 @@ fn record_killed_borrows_for_local(
all_facts: &mut AllFacts,
borrow_set: &BorrowSet<'_>,
location_table: &LocationTable,
local: &Local,
local: Local,
location: Location,
) {
if let Some(borrow_indices) = borrow_set.local_map.get(local) {
if let Some(borrow_indices) = borrow_set.local_map.get(&local) {
all_facts.killed.reserve(borrow_indices.len());
for &borrow_index in borrow_indices {
let location_index = location_table.mid_index(location);

View File

@ -604,8 +604,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
cursor = proj_base;
match elem {
ProjectionElem::Field(field, _) if union_ty(local, proj_base).is_some() => {
return Some((PlaceRef { local, projection: proj_base }, field));
ProjectionElem::Field(field, _)
if union_ty(*local, proj_base).is_some() =>
{
return Some((
PlaceRef { local: *local, projection: proj_base },
field,
));
}
_ => {}
}
@ -622,14 +627,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
cursor = proj_base;
if let ProjectionElem::Field(field, _) = elem {
if let Some(union_ty) = union_ty(local, proj_base) {
if let Some(union_ty) = union_ty(*local, proj_base) {
if field != target_field
&& local == target_base.local
&& *local == target_base.local
&& proj_base == target_base.projection
{
// FIXME when we avoid clone reuse describe_place closure
let describe_base_place = self
.describe_place(PlaceRef { local, projection: proj_base })
.describe_place(PlaceRef {
local: *local,
projection: proj_base,
})
.unwrap_or_else(|| "_".to_owned());
return Some((
@ -686,12 +694,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let borrow_span = borrow_spans.var_or_use();
assert!(root_place.projection.is_empty());
let proper_span = self.body.local_decls[*root_place.local].source_info.span;
let proper_span = self.body.local_decls[root_place.local].source_info.span;
let root_place_projection = self.infcx.tcx.intern_place_elems(root_place.projection);
if self.access_place_error_reported.contains(&(
Place { local: *root_place.local, projection: root_place_projection },
Place { local: root_place.local, projection: root_place_projection },
borrow_span,
)) {
debug!(
@ -702,7 +710,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
self.access_place_error_reported.insert((
Place { local: *root_place.local, projection: root_place_projection },
Place { local: root_place.local, projection: root_place_projection },
borrow_span,
));
@ -1139,7 +1147,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let root_place =
self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All).last().unwrap();
let local = root_place.local;
match self.body.local_kind(*local) {
match self.body.local_kind(local) {
LocalKind::ReturnPointer | LocalKind::Temp => {
("temporary value".to_string(), "temporary value created here".to_string())
}
@ -1513,9 +1521,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
StorageDeadOrDrop::LocalStorageDead
| StorageDeadOrDrop::BoxedStorageDead => {
assert!(
Place::ty_from(&place.local, proj_base, *self.body, tcx)
.ty
.is_box(),
Place::ty_from(place.local, proj_base, *self.body, tcx).ty.is_box(),
"Drop of value behind a reference or raw pointer"
);
StorageDeadOrDrop::BoxedStorageDead
@ -1523,7 +1529,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
StorageDeadOrDrop::Destructor(_) => base_access,
},
ProjectionElem::Field(..) | ProjectionElem::Downcast(..) => {
let base_ty = Place::ty_from(&place.local, proj_base, *self.body, tcx).ty;
let base_ty = Place::ty_from(place.local, proj_base, *self.body, tcx).ty;
match base_ty.kind {
ty::Adt(def, _) if def.has_dtor(tcx) => {
// Report the outermost adt with a destructor

View File

@ -169,10 +169,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
) -> Result<(), ()> {
match place {
PlaceRef { local, projection: [] } => {
self.append_local_to_string(*local, buf)?;
self.append_local_to_string(local, buf)?;
}
PlaceRef { local, projection: [ProjectionElem::Deref] }
if self.body.local_decls[*local].is_ref_for_guard() =>
if self.body.local_decls[local].is_ref_for_guard() =>
{
self.append_place_to_string(
PlaceRef { local: local, projection: &[] },
@ -182,9 +182,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
)?;
}
PlaceRef { local, projection: [ProjectionElem::Deref] }
if self.body.local_decls[*local].is_ref_to_static() =>
if self.body.local_decls[local].is_ref_to_static() =>
{
let local_info = &self.body.local_decls[*local].local_info;
let local_info = &self.body.local_decls[local].local_info;
if let LocalInfo::StaticRef { def_id, .. } = *local_info {
buf.push_str(&self.infcx.tcx.item_name(def_id).as_str());
} else {
@ -307,7 +307,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// FIXME Place2 Make this work iteratively
match place {
PlaceRef { local, projection: [] } => {
let local = &self.body.local_decls[*local];
let local = &self.body.local_decls[local];
self.describe_field_from_ty(&local.ty, field, None)
}
PlaceRef { local, projection: [proj_base @ .., elem] } => match elem {

View File

@ -274,8 +274,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let description = if place.projection.len() == 1 {
format!("static item `{}`", self.describe_place(place.as_ref()).unwrap())
} else {
let base_static =
PlaceRef { local: &place.local, projection: &[ProjectionElem::Deref] };
let base_static = PlaceRef { local: place.local, projection: &[ProjectionElem::Deref] };
format!(
"`{:?}` as `{:?}` is a static item",
@ -304,17 +303,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let deref_base = match deref_target_place.projection.as_ref() {
&[ref proj_base @ .., ProjectionElem::Deref] => {
PlaceRef { local: &deref_target_place.local, projection: &proj_base }
PlaceRef { local: deref_target_place.local, projection: &proj_base }
}
_ => bug!("deref_target_place is not a deref projection"),
};
if let PlaceRef { local, projection: [] } = deref_base {
let decl = &self.body.local_decls[*local];
let decl = &self.body.local_decls[local];
if decl.is_ref_for_guard() {
let mut err = self.cannot_move_out_of(
span,
&format!("`{}` in pattern guard", self.local_names[*local].unwrap()),
&format!("`{}` in pattern guard", self.local_names[local].unwrap()),
);
err.note(
"variables bound in patterns cannot be moved from \

View File

@ -47,7 +47,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if access_place.as_local().is_some() {
reason = ", as it is not declared as mutable".to_string();
} else {
let name = self.local_names[*local].expect("immutable unnamed local");
let name = self.local_names[local].expect("immutable unnamed local");
reason = format!(", as `{}` is not declared as mutable", name);
}
}
@ -70,20 +70,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
PlaceRef { local, projection: [ProjectionElem::Deref] }
if self.body.local_decls[*local].is_ref_for_guard() =>
if self.body.local_decls[local].is_ref_for_guard() =>
{
item_msg = format!("`{}`", access_place_desc.unwrap());
reason = ", as it is immutable for the pattern guard".to_string();
}
PlaceRef { local, projection: [ProjectionElem::Deref] }
if self.body.local_decls[*local].is_ref_to_static() =>
if self.body.local_decls[local].is_ref_to_static() =>
{
if access_place.projection.len() == 1 {
item_msg = format!("immutable static item `{}`", access_place_desc.unwrap());
reason = String::new();
} else {
item_msg = format!("`{}`", access_place_desc.unwrap());
let local_info = &self.body.local_decls[*local].local_info;
let local_info = &self.body.local_decls[local].local_info;
if let LocalInfo::StaticRef { def_id, .. } = *local_info {
let static_name = &self.infcx.tcx.item_name(def_id);
reason = format!(", as `{}` is an immutable static item", static_name);
@ -93,7 +93,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
}
PlaceRef { local: _, projection: [proj_base @ .., ProjectionElem::Deref] } => {
if *the_place_err.local == Local::new(1)
if the_place_err.local == Local::new(1)
&& proj_base.is_empty()
&& !self.upvars.is_empty()
{
@ -212,7 +212,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if {
self.body
.local_decls
.get(*local)
.get(local)
.map(|local_decl| {
if let LocalInfo::User(ClearCrossCrate::Set(
mir::BindingForm::ImplicitSelf(kind),
@ -224,7 +224,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// Deliberately fall into this case for all implicit self types,
// so that we don't fall in to the next case with them.
kind == mir::ImplicitSelfKind::MutRef
} else if Some(kw::SelfLower) == self.local_names[*local] {
} else if Some(kw::SelfLower) == self.local_names[local] {
// Otherwise, check if the name is the self kewyord - in which case
// we have an explicit self. Do the same thing in this case and check
// for a `self: &mut Self` to suggest removing the `&mut`.
@ -247,20 +247,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// We want to suggest users use `let mut` for local (user
// variable) mutations...
PlaceRef { local, projection: [] }
if self.body.local_decls[*local].can_be_made_mutable() =>
if self.body.local_decls[local].can_be_made_mutable() =>
{
// ... but it doesn't make sense to suggest it on
// variables that are `ref x`, `ref mut x`, `&self`,
// or `&mut self` (such variables are simply not
// mutable).
let local_decl = &self.body.local_decls[*local];
let local_decl = &self.body.local_decls[local];
assert_eq!(local_decl.mutability, Mutability::Not);
err.span_label(span, format!("cannot {ACT}", ACT = act));
err.span_suggestion(
local_decl.source_info.span,
"consider changing this to be mutable",
format!("mut {}", self.local_names[*local].unwrap()),
format!("mut {}", self.local_names[local].unwrap()),
Applicability::MachineApplicable,
);
}
@ -312,7 +312,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
PlaceRef { local, projection: [ProjectionElem::Deref] }
if self.body.local_decls[*local].is_ref_for_guard() =>
if self.body.local_decls[local].is_ref_for_guard() =>
{
err.span_label(span, format!("cannot {ACT}", ACT = act));
err.note(
@ -326,9 +326,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// FIXME: can this case be generalized to work for an
// arbitrary base for the projection?
PlaceRef { local, projection: [ProjectionElem::Deref] }
if self.body.local_decls[*local].is_user_variable() =>
if self.body.local_decls[local].is_user_variable() =>
{
let local_decl = &self.body.local_decls[*local];
let local_decl = &self.body.local_decls[local];
let suggestion = match local_decl.local_info {
LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::ImplicitSelf(_))) => {
Some(suggest_ampmut_self(self.infcx.tcx, local_decl))
@ -343,7 +343,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
))) => Some(suggest_ampmut(
self.infcx.tcx,
self.body,
*local,
local,
local_decl,
opt_ty_info,
)),
@ -379,7 +379,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
);
}
match self.local_names[*local] {
match self.local_names[local] {
Some(name) if !local_decl.from_compiler_desugaring() => {
err.span_label(
span,
@ -411,7 +411,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
local,
projection: [ProjectionElem::Deref],
// FIXME document what is this 1 magic number about
} if *local == Local::new(1) && !self.upvars.is_empty() => {
} if local == Local::new(1) && !self.upvars.is_empty() => {
err.span_label(span, format!("cannot {ACT}", ACT = act));
err.span_help(
self.body.span,

View File

@ -823,7 +823,7 @@ enum InitializationRequiringAction {
}
struct RootPlace<'d, 'tcx> {
place_local: &'d Local,
place_local: Local,
place_projection: &'d [PlaceElem<'tcx>],
is_local_mutation_allowed: LocalMutationIsAllowed,
}
@ -1382,7 +1382,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
debug!("check_for_invalidation_at_exit({:?})", borrow);
let place = &borrow.borrowed_place;
let deref = [ProjectionElem::Deref];
let mut root_place = PlaceRef { local: &place.local, projection: &[] };
let mut root_place = PlaceRef { local: place.local, projection: &[] };
// FIXME(nll-rfc#40): do more precise destructor tracking here. For now
// we just know that all locals are dropped at function exit (otherwise
@ -1391,7 +1391,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// FIXME: allow thread-locals to borrow other thread locals?
let (might_be_alive, will_be_dropped) =
if self.body.local_decls[*root_place.local].is_ref_to_thread_local() {
if self.body.local_decls[root_place.local].is_ref_to_thread_local() {
// Thread-locals might be dropped after the function exits
// We have to dereference the outer reference because
// borrows don't conflict behind shared references.
@ -1722,7 +1722,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
self.check_if_full_path_is_moved(
location, InitializationRequiringAction::Use,
(PlaceRef {
local: &place.local,
local: place.local,
projection: proj_base,
}, span), flow_state);
// (base initialized; no need to
@ -1740,13 +1740,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// assigning to `P.f` requires `P` itself
// be already initialized
let tcx = self.infcx.tcx;
let base_ty = Place::ty_from(&place.local, proj_base, self.body(), tcx).ty;
let base_ty = Place::ty_from(place.local, proj_base, self.body(), tcx).ty;
match base_ty.kind {
ty::Adt(def, _) if def.has_dtor(tcx) => {
self.check_if_path_or_subpath_is_moved(
location, InitializationRequiringAction::Assignment,
(PlaceRef {
local: &place.local,
local: place.local,
projection: proj_base,
}, span), flow_state);
@ -1759,7 +1759,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// is allowed, remove this match arm.
ty::Adt(..) | ty::Tuple(..) => {
check_parent_of_field(self, location, PlaceRef {
local: &place.local,
local: place.local,
projection: proj_base,
}, span, flow_state);
@ -1998,9 +1998,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// mutated, then it is justified to be annotated with the `mut`
// keyword, since the mutation may be a possible reassignment.
if is_local_mutation_allowed != LocalMutationIsAllowed::Yes
&& self.is_local_ever_initialized(*local, flow_state).is_some()
&& self.is_local_ever_initialized(local, flow_state).is_some()
{
self.used_mut.insert(*local);
self.used_mut.insert(local);
}
}
RootPlace {
@ -2032,7 +2032,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
) -> Result<RootPlace<'d, 'tcx>, PlaceRef<'d, 'tcx>> {
match place {
PlaceRef { local, projection: [] } => {
let local = &self.body.local_decls[*local];
let local = &self.body.local_decls[local];
match local.mutability {
Mutability::Not => match is_local_mutation_allowed {
LocalMutationIsAllowed::Yes => Ok(RootPlace {

View File

@ -48,7 +48,7 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
let proj_base = &self.projection[..i];
if *elem == ProjectionElem::Deref {
let ty = Place::ty_from(&self.local, proj_base, body, tcx).ty;
let ty = Place::ty_from(self.local, proj_base, body, tcx).ty;
match ty.kind {
ty::Ref(_, _, hir::Mutability::Not) if i == 0 => {
// For references to thread-local statics, we do need

View File

@ -119,7 +119,7 @@ fn place_components_conflict<'tcx>(
// and either equal or disjoint.
// - If we did run out of access, the borrow can access a part of it.
let borrow_local = &borrow_place.local;
let borrow_local = borrow_place.local;
let access_local = access_place.local;
match place_base_conflict(borrow_local, access_local) {
@ -293,7 +293,7 @@ fn place_components_conflict<'tcx>(
// Given that the bases of `elem1` and `elem2` are always either equal
// or disjoint (and have the same type!), return the overlap situation
// between `elem1` and `elem2`.
fn place_base_conflict(l1: &Local, l2: &Local) -> Overlap {
fn place_base_conflict(l1: Local, l2: Local) -> Overlap {
if l1 == l2 {
// the same local - base case, equal
debug!("place_element_conflict: DISJOINT-OR-EQ-LOCAL");
@ -311,7 +311,7 @@ fn place_base_conflict(l1: &Local, l2: &Local) -> Overlap {
fn place_projection_conflict<'tcx>(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
pi1_local: &Local,
pi1_local: Local,
pi1_proj_base: &[PlaceElem<'tcx>],
pi1_elem: &PlaceElem<'tcx>,
pi2_elem: &PlaceElem<'tcx>,

View File

@ -2390,7 +2390,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
match elem {
ProjectionElem::Deref => {
let tcx = self.infcx.tcx;
let base_ty = Place::ty_from(&borrowed_place.local, proj_base, body, tcx).ty;
let base_ty = Place::ty_from(borrowed_place.local, proj_base, body, tcx).ty;
debug!("add_reborrow_constraint - base_ty = {:?}", base_ty);
match base_ty.kind {

View File

@ -109,7 +109,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
let proj_base = &place.projection[..i];
let body = self.builder.body;
let tcx = self.builder.tcx;
let place_ty = Place::ty_from(&place.local, proj_base, body, tcx).ty;
let place_ty = Place::ty_from(place.local, proj_base, body, tcx).ty;
match place_ty.kind {
ty::Ref(..) | ty::RawPtr(..) => {
let proj = &place.projection[..i + 1];

View File

@ -246,7 +246,7 @@ impl MovePathLookup {
// unknown place, but will rather return the nearest available
// parent.
pub fn find(&self, place: PlaceRef<'_, '_>) -> LookupResult {
let mut result = self.locals[*place.local];
let mut result = self.locals[place.local];
for elem in place.projection.iter() {
if let Some(&subpath) = self.projections.get(&(result, elem.lift())) {

View File

@ -78,7 +78,7 @@ pub trait Qualif {
place: PlaceRef<'_, 'tcx>,
) -> bool {
match place {
PlaceRef { local, projection: [] } => per_local(*local),
PlaceRef { local, projection: [] } => per_local(local),
PlaceRef { local: _, projection: [.., _] } => Self::in_projection(cx, per_local, place),
}
}
@ -149,12 +149,12 @@ pub trait Qualif {
Rvalue::Ref(_, _, ref place) | Rvalue::AddressOf(_, ref place) => {
// Special-case reborrows to be more like a copy of the reference.
if let [proj_base @ .., ProjectionElem::Deref] = place.projection.as_ref() {
let base_ty = Place::ty_from(&place.local, proj_base, *cx.body, cx.tcx).ty;
let base_ty = Place::ty_from(place.local, proj_base, *cx.body, cx.tcx).ty;
if let ty::Ref(..) = base_ty.kind {
return Self::in_place(
cx,
per_local,
PlaceRef { local: &place.local, projection: proj_base },
PlaceRef { local: place.local, projection: proj_base },
);
}
}

View File

@ -48,7 +48,7 @@ where
match (value, place.as_ref()) {
(true, mir::PlaceRef { local, .. }) => {
self.qualifs_per_local.insert(*local);
self.qualifs_per_local.insert(local);
}
// For now, we do not clear the qualif if a local is overwritten in full by

View File

@ -448,7 +448,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
match elem {
ProjectionElem::Deref => {
let base_ty = Place::ty_from(place_local, proj_base, *self.body, self.tcx).ty;
let base_ty = Place::ty_from(*place_local, proj_base, *self.body, self.tcx).ty;
if let ty::RawPtr(_) = base_ty.kind {
if proj_base.is_empty() {
if let (local, []) = (place_local, proj_base) {
@ -472,7 +472,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
| ProjectionElem::Subslice { .. }
| ProjectionElem::Field(..)
| ProjectionElem::Index(_) => {
let base_ty = Place::ty_from(place_local, proj_base, *self.body, self.tcx).ty;
let base_ty = Place::ty_from(*place_local, proj_base, *self.body, self.tcx).ty;
match base_ty.ty_adt_def() {
Some(def) if def.is_union() => {
self.check_op(ops::UnionAccess);
@ -664,7 +664,7 @@ fn place_as_reborrow(
//
// This is sufficient to prevent an access to a `static mut` from being marked as a
// reborrow, even if the check above were to disappear.
let inner_ty = Place::ty_from(&place.local, inner, body, tcx).ty;
let inner_ty = Place::ty_from(place.local, inner, body, tcx).ty;
match inner_ty.kind {
ty::Ref(..) => Some(inner),
_ => None,

View File

@ -215,7 +215,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
}
}
let is_borrow_of_interior_mut = context.is_borrow()
&& !Place::ty_from(&place.local, proj_base, self.body, self.tcx).ty.is_freeze(
&& !Place::ty_from(place.local, proj_base, self.body, self.tcx).ty.is_freeze(
self.tcx,
self.param_env,
self.source_info.span,
@ -260,7 +260,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
}
}
}
let base_ty = Place::ty_from(&place.local, proj_base, self.body, self.tcx).ty;
let base_ty = Place::ty_from(place.local, proj_base, self.body, self.tcx).ty;
match base_ty.kind {
ty::RawPtr(..) => self.require_unsafe(
"dereference of raw pointer",
@ -414,8 +414,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
match elem {
ProjectionElem::Field(..) => {
let ty =
Place::ty_from(&place.local, proj_base, &self.body.local_decls, self.tcx)
.ty;
Place::ty_from(place.local, proj_base, &self.body.local_decls, self.tcx).ty;
match ty.kind {
ty::Adt(def, _) => match self.tcx.layout_scalar_valid_range(def.did) {
(Bound::Unbounded, Bound::Unbounded) => {}

View File

@ -640,8 +640,8 @@ impl<'a, 'tcx> Integrator<'a, 'tcx> {
new
}
fn make_integrate_local(&self, local: &Local) -> Local {
if *local == RETURN_PLACE {
fn make_integrate_local(&self, local: Local) -> Local {
if local == RETURN_PLACE {
return self.destination.local;
}
@ -660,7 +660,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
}
fn visit_local(&mut self, local: &mut Local, _ctxt: PlaceContext, _location: Location) {
*local = self.make_integrate_local(local);
*local = self.make_integrate_local(*local);
}
fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) {
@ -680,7 +680,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
if let PlaceElem::Index(local) = elem {
let new_local = self.make_integrate_local(local);
let new_local = self.make_integrate_local(*local);
if new_local != *local {
return Some(PlaceElem::Index(new_local));

View File

@ -329,7 +329,7 @@ impl<'tcx> Validator<'_, 'tcx> {
// FIXME(eddyb) this is probably excessive, with
// the exception of `union` member accesses.
let ty =
Place::ty_from(&place.local, proj_base, *self.body, self.tcx)
Place::ty_from(place.local, proj_base, *self.body, self.tcx)
.projection_ty(self.tcx, elem)
.ty;
if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) {
@ -475,7 +475,7 @@ impl<'tcx> Validator<'_, 'tcx> {
fn validate_place(&self, place: PlaceRef<'_, 'tcx>) -> Result<(), Unpromotable> {
match place {
PlaceRef { local, projection: [] } => self.validate_local(*local),
PlaceRef { local, projection: [] } => self.validate_local(local),
PlaceRef { local: _, projection: [proj_base @ .., elem] } => {
match *elem {
ProjectionElem::Deref | ProjectionElem::Downcast(..) => {
@ -589,10 +589,10 @@ impl<'tcx> Validator<'_, 'tcx> {
// Raw reborrows can come from reference to pointer coercions,
// so are allowed.
if let [proj_base @ .., ProjectionElem::Deref] = place.projection.as_ref() {
let base_ty = Place::ty_from(&place.local, proj_base, *self.body, self.tcx).ty;
let base_ty = Place::ty_from(place.local, proj_base, *self.body, self.tcx).ty;
if let ty::Ref(..) = base_ty.kind {
return self.validate_place(PlaceRef {
local: &place.local,
local: place.local,
projection: proj_base,
});
}
@ -628,9 +628,9 @@ impl<'tcx> Validator<'_, 'tcx> {
// Special-case reborrows to be more like a copy of the reference.
let mut place = place.as_ref();
if let [proj_base @ .., ProjectionElem::Deref] = &place.projection {
let base_ty = Place::ty_from(&place.local, proj_base, *self.body, self.tcx).ty;
let base_ty = Place::ty_from(place.local, proj_base, *self.body, self.tcx).ty;
if let ty::Ref(..) = base_ty.kind {
place = PlaceRef { local: &place.local, projection: proj_base };
place = PlaceRef { local: place.local, projection: proj_base };
}
}
@ -640,7 +640,7 @@ impl<'tcx> Validator<'_, 'tcx> {
// `<HasMutInterior as Qualif>::in_projection` from
// `check_consts::qualifs` but without recursion.
let mut has_mut_interior =
self.qualif_local::<qualifs::HasMutInterior>(*place.local);
self.qualif_local::<qualifs::HasMutInterior>(place.local);
if has_mut_interior {
let mut place_projection = place.projection;
// FIXME(eddyb) use a forward loop instead of a reverse one.

View File

@ -268,7 +268,7 @@ fn check_place(
ProjectionElem::Downcast(_symbol, _variant_index) => {}
ProjectionElem::Field(..) => {
let base_ty = Place::ty_from(&place.local, &proj_base, body, tcx).ty;
let base_ty = Place::ty_from(place.local, &proj_base, body, tcx).ty;
if let Some(def) = base_ty.ty_adt_def() {
// No union field accesses in `const fn`
if def.is_union() {

View File

@ -139,7 +139,7 @@ fn match_variant_field_place<'tcx>(place: &Place<'tcx>) -> Option<(Local, VarFie
PlaceRef {
local,
projection: &[ProjectionElem::Downcast(_, var_idx), ProjectionElem::Field(field, ty)],
} => Some((*local, VarField { field, field_ty: ty, var_idx })),
} => Some((local, VarField { field, field_ty: ty, var_idx })),
_ => None,
}
}

View File

@ -46,7 +46,7 @@ where
// encountered a Deref, which is ABI-aligned
ProjectionElem::Deref => break,
ProjectionElem::Field(..) => {
let ty = Place::ty_from(&place.local, proj_base, local_decls, tcx).ty;
let ty = Place::ty_from(place.local, proj_base, local_decls, tcx).ty;
match ty.kind {
ty::Adt(def, _) if def.repr.packed() => return true,
_ => {}

View File

@ -364,7 +364,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
) {
let tcx = self.hir.tcx();
let place_ty =
Place::ty_from(&base_place.local, &base_place.projection, &self.local_decls, tcx);
Place::ty_from(base_place.local, &base_place.projection, &self.local_decls, tcx);
if let ty::Slice(_) = place_ty.ty.kind {
// We need to create fake borrows to ensure that the bounds
// check that we just did stays valid. Since we can't assign to
@ -374,7 +374,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
match elem {
ProjectionElem::Deref => {
let fake_borrow_deref_ty = Place::ty_from(
&base_place.local,
base_place.local,
&base_place.projection[..idx],
&self.local_decls,
tcx,
@ -399,7 +399,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
ProjectionElem::Index(_) => {
let index_ty = Place::ty_from(
&base_place.local,
base_place.local,
&base_place.projection[..idx],
&self.local_decls,
tcx,

View File

@ -393,20 +393,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let arg_place = unpack!(block = this.as_place(block, arg));
let mutability = match arg_place.as_ref() {
PlaceRef { local, projection: &[] } => this.local_decls[*local].mutability,
PlaceRef { local, projection: &[] } => this.local_decls[local].mutability,
PlaceRef { local, projection: &[ProjectionElem::Deref] } => {
debug_assert!(
this.local_decls[*local].is_ref_for_guard(),
this.local_decls[local].is_ref_for_guard(),
"Unexpected capture place",
);
this.local_decls[*local].mutability
this.local_decls[local].mutability
}
PlaceRef {
ref local,
local,
projection: &[ref proj_base @ .., ProjectionElem::Field(upvar_index, _)],
}
| PlaceRef {
ref local,
local,
projection:
&[ref proj_base @ .., ProjectionElem::Field(upvar_index, _), ProjectionElem::Deref],
} => {

View File

@ -1241,7 +1241,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Insert a shallow borrow after a deref. For other
// projections the borrow of prefix_cursor will
// conflict with any mutation of base.
all_fake_borrows.push(PlaceRef { local: &place.local, projection: proj_base });
all_fake_borrows.push(PlaceRef { local: place.local, projection: proj_base });
}
}
@ -1258,7 +1258,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.into_iter()
.map(|matched_place_ref| {
let matched_place = Place {
local: *matched_place_ref.local,
local: matched_place_ref.local,
projection: tcx.intern_place_elems(matched_place_ref.projection),
};
let fake_borrow_deref_ty = matched_place.ty(&self.local_decls, tcx).ty;