mirror of https://github.com/rust-lang/rust.git
Local field on PlaceRef and RootPlace is not a reference anymore
This commit is contained in:
parent
39d93b1ef8
commit
b5b6be0ab7
|
@ -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>],
|
||||
}
|
||||
|
||||
|
@ -1798,7 +1798,7 @@ impl<'tcx> Place<'tcx> {
|
|||
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: &[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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,13 +128,13 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
|
|||
};
|
||||
if is_consume {
|
||||
let base_ty =
|
||||
mir::Place::ty_from(place_ref.local, proj_base, *self.fx.mir, cx.tcx());
|
||||
mir::Place::ty_from(&place_ref.local, proj_base, *self.fx.mir, cx.tcx());
|
||||
let base_ty = self.fx.monomorphize(&base_ty);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -373,7 +373,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
) -> 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() {
|
||||
|
|
|
@ -415,7 +415,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
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;
|
||||
}
|
||||
|
@ -499,7 +499,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
|
||||
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);
|
||||
let place_ty = mir::Place::ty_from(&place_ref.local, place_ref.projection, *self.mir, tcx);
|
||||
self.monomorphize(&place_ty.ty)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
|
|||
all_facts,
|
||||
self.borrow_set,
|
||||
self.location_table,
|
||||
*local,
|
||||
local,
|
||||
location,
|
||||
);
|
||||
}
|
||||
|
@ -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,
|
||||
|
|
|
@ -186,7 +186,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
let ty =
|
||||
Place::ty_from(used_place.local, used_place.projection, *self.body, self.infcx.tcx)
|
||||
Place::ty_from(&used_place.local, used_place.projection, *self.body, self.infcx.tcx)
|
||||
.ty;
|
||||
let needs_note = match ty.kind {
|
||||
ty::Closure(id, _) => {
|
||||
|
@ -605,7 +605,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
|
||||
match elem {
|
||||
ProjectionElem::Field(field, _) if union_ty(local, proj_base).is_some() => {
|
||||
return Some((PlaceRef { local, projection: proj_base }, field));
|
||||
return Some((PlaceRef { local: *local, projection: proj_base }, field));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -624,12 +624,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
if let ProjectionElem::Field(field, _) = elem {
|
||||
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,7 +686,7 @@ 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);
|
||||
|
||||
|
@ -1139,7 +1139,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())
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -316,7 +316,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
}
|
||||
ProjectionElem::Downcast(_, variant_index) => {
|
||||
let base_ty =
|
||||
Place::ty_from(place.local, place.projection, *self.body, self.infcx.tcx)
|
||||
Place::ty_from(&place.local, place.projection, *self.body, self.infcx.tcx)
|
||||
.ty;
|
||||
self.describe_field_from_ty(&base_ty, field, Some(*variant_index))
|
||||
}
|
||||
|
@ -447,7 +447,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
|
||||
// If we didn't find an overloaded deref or index, then assume it's a
|
||||
// built in deref and check the type of the base.
|
||||
let base_ty = Place::ty_from(deref_base.local, deref_base.projection, *self.body, tcx).ty;
|
||||
let base_ty = Place::ty_from(&deref_base.local, deref_base.projection, *self.body, tcx).ty;
|
||||
if base_ty.is_unsafe_ptr() {
|
||||
BorrowedContentSource::DerefRawPointer
|
||||
} else if base_ty.is_mutable_ptr() {
|
||||
|
|
|
@ -275,7 +275,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
format!("static item `{}`", self.describe_place(place.as_ref()).unwrap())
|
||||
} else {
|
||||
let base_static =
|
||||
PlaceRef { local: &place.local, projection: &[ProjectionElem::Deref] };
|
||||
PlaceRef { local: place.local, projection: &[ProjectionElem::Deref] };
|
||||
|
||||
format!(
|
||||
"`{:?}` as `{:?}` is a static item",
|
||||
|
@ -304,17 +304,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 \
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
|
||||
} => {
|
||||
debug_assert!(is_closure_or_generator(
|
||||
Place::ty_from(local, proj_base, *self.body, self.infcx.tcx).ty
|
||||
Place::ty_from(&local, proj_base, *self.body, self.infcx.tcx).ty
|
||||
));
|
||||
|
||||
item_msg = format!("`{}`", access_place_desc.unwrap());
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -101,7 +101,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
debug_assert!(self.body.local_decls[Local::new(1)].ty.is_region_ptr());
|
||||
debug_assert!(is_closure_or_generator(
|
||||
Place::ty_from(
|
||||
the_place_err.local,
|
||||
&the_place_err.local,
|
||||
the_place_err.projection,
|
||||
*self.body,
|
||||
self.infcx.tcx
|
||||
|
@ -195,7 +195,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
|
||||
if let Some((span, message)) = annotate_struct_field(
|
||||
self.infcx.tcx,
|
||||
Place::ty_from(local, proj_base, *self.body, self.infcx.tcx).ty,
|
||||
Place::ty_from(&local, proj_base, *self.body, self.infcx.tcx).ty,
|
||||
field,
|
||||
) {
|
||||
err.span_suggestion(
|
||||
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
|
||||
} => {
|
||||
debug_assert!(is_closure_or_generator(
|
||||
Place::ty_from(local, proj_base, *self.body, self.infcx.tcx).ty
|
||||
Place::ty_from(&local, proj_base, *self.body, self.infcx.tcx).ty
|
||||
));
|
||||
|
||||
err.span_label(span, format!("cannot {ACT}", ACT = act));
|
||||
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
@ -1623,7 +1623,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
place_span.0.projection
|
||||
{
|
||||
let place_ty =
|
||||
Place::ty_from(place_span.0.local, base_proj, self.body(), self.infcx.tcx);
|
||||
Place::ty_from(&place_span.0.local, base_proj, self.body(), self.infcx.tcx);
|
||||
if let ty::Array(..) = place_ty.ty.kind {
|
||||
let array_place = PlaceRef { local: place_span.0.local, projection: base_proj };
|
||||
self.check_if_subslice_element_is_moved(
|
||||
|
@ -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
|
||||
|
@ -1746,7 +1746,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, '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);
|
||||
|
||||
|
@ -1844,7 +1844,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
// of the union - we should error in that case.
|
||||
let tcx = this.infcx.tcx;
|
||||
if let ty::Adt(def, _) =
|
||||
Place::ty_from(base.local, base.projection, this.body(), tcx).ty.kind
|
||||
Place::ty_from(&base.local, base.projection, this.body(), tcx).ty.kind
|
||||
{
|
||||
if def.is_union() {
|
||||
if this.move_data.path_map[mpi].iter().any(|moi| {
|
||||
|
@ -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 {
|
||||
|
@ -2058,7 +2058,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
match elem {
|
||||
ProjectionElem::Deref => {
|
||||
let base_ty =
|
||||
Place::ty_from(place.local, proj_base, self.body(), self.infcx.tcx).ty;
|
||||
Place::ty_from(&place.local, proj_base, self.body(), self.infcx.tcx).ty;
|
||||
|
||||
// Check the kind of deref to decide
|
||||
match base_ty.kind {
|
||||
|
@ -2192,7 +2192,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
match place_projection {
|
||||
[base @ .., ProjectionElem::Field(field, _ty)] => {
|
||||
let tcx = self.infcx.tcx;
|
||||
let base_ty = Place::ty_from(place_ref.local, base, self.body(), tcx).ty;
|
||||
let base_ty = Place::ty_from(&place_ref.local, base, self.body(), tcx).ty;
|
||||
|
||||
if (base_ty.is_closure() || base_ty.is_generator())
|
||||
&& (!by_ref || self.upvars[field.index()].by_ref)
|
||||
|
|
|
@ -122,7 +122,7 @@ fn place_components_conflict<'tcx>(
|
|||
let borrow_local = borrow_place.local;
|
||||
let access_local = access_place.local;
|
||||
|
||||
match place_base_conflict(borrow_local, *access_local) {
|
||||
match place_base_conflict(borrow_local, access_local) {
|
||||
Overlap::Arbitrary => {
|
||||
bug!("Two base can't return Arbitrary");
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
|
|||
// derefs, except we stop at the deref of a shared
|
||||
// reference.
|
||||
|
||||
let ty = Place::ty_from(cursor.local, proj_base, *self.body, self.tcx).ty;
|
||||
let ty = Place::ty_from(&cursor.local, proj_base, *self.body, self.tcx).ty;
|
||||
match ty.kind {
|
||||
ty::RawPtr(_) | ty::Ref(_ /*rgn*/, _ /*ty*/, hir::Mutability::Not) => {
|
||||
// don't continue traversing over derefs of raw pointers or shared
|
||||
|
|
|
@ -490,7 +490,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
|||
// of the union so it is marked as initialized again.
|
||||
if let [proj_base @ .., ProjectionElem::Field(_, _)] = place.projection {
|
||||
if let ty::Adt(def, _) =
|
||||
Place::ty_from(place.local, proj_base, self.builder.body, self.builder.tcx).ty.kind
|
||||
Place::ty_from(&place.local, proj_base, self.builder.body, self.builder.tcx).ty.kind
|
||||
{
|
||||
if def.is_union() {
|
||||
place = PlaceRef { local: place.local, projection: proj_base }
|
||||
|
|
|
@ -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())) {
|
||||
|
|
|
@ -46,7 +46,7 @@ pub trait Qualif {
|
|||
let qualif = base_qualif
|
||||
&& Self::in_any_value_of_ty(
|
||||
cx,
|
||||
Place::ty_from(place.local, proj_base, *cx.body, cx.tcx)
|
||||
Place::ty_from(&place.local, proj_base, *cx.body, cx.tcx)
|
||||
.projection_ty(cx.tcx, elem)
|
||||
.ty,
|
||||
);
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ pub trait Qualif {
|
|||
return Self::in_place(
|
||||
cx,
|
||||
per_local,
|
||||
PlaceRef { local: &place.local, projection: proj_base },
|
||||
PlaceRef { local: place.local, projection: proj_base },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -95,7 +95,7 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {
|
|||
if let PlaceRef { local, projection: &[ref proj_base @ .., ProjectionElem::Deref] } =
|
||||
place.as_ref()
|
||||
{
|
||||
if Place::ty_from(local, proj_base, self.body, self.tcx).ty.is_region_ptr() {
|
||||
if Place::ty_from(&local, proj_base, self.body, self.tcx).ty.is_region_ptr() {
|
||||
self.optimizations.and_stars.insert(location);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(..) => {
|
||||
|
@ -491,7 +491,7 @@ impl<'tcx> Validator<'_, 'tcx> {
|
|||
ProjectionElem::Field(..) => {
|
||||
if self.const_kind.is_none() {
|
||||
let base_ty =
|
||||
Place::ty_from(place.local, proj_base, *self.body, self.tcx).ty;
|
||||
Place::ty_from(&place.local, proj_base, *self.body, self.tcx).ty;
|
||||
if let Some(def) = base_ty.ty_adt_def() {
|
||||
// No promotion of union field accesses.
|
||||
if def.is_union() {
|
||||
|
@ -592,7 +592,7 @@ impl<'tcx> Validator<'_, 'tcx> {
|
|||
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,
|
||||
});
|
||||
}
|
||||
|
@ -630,7 +630,7 @@ impl<'tcx> Validator<'_, 'tcx> {
|
|||
if let [proj_base @ .., ProjectionElem::Deref] = &place.projection {
|
||||
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,14 +640,14 @@ 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.
|
||||
while let [proj_base @ .., elem] = place_projection {
|
||||
// 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)
|
||||
let ty = 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) {
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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],
|
||||
} => {
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue