Place::ty_from takes local by value

This commit is contained in:
Santiago Pastorino 2020-01-14 02:21:42 -03:00
parent b5b6be0ab7
commit 22a4827dcb
No known key found for this signature in database
GPG Key ID: 88C941CDA1D46432
20 changed files with 47 additions and 47 deletions

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

@ -128,7 +128,7 @@ 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.

View File

@ -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)
}
}

View File

@ -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, _) => {
@ -604,7 +604,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
cursor = proj_base;
match elem {
ProjectionElem::Field(field, _) if union_ty(local, proj_base).is_some() => {
ProjectionElem::Field(field, _) if union_ty(*local, proj_base).is_some() => {
return Some((PlaceRef { local: *local, projection: proj_base }, field));
}
_ => {}
@ -622,7 +622,7 @@ 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
&& proj_base == target_base.projection
@ -1513,7 +1513,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
StorageDeadOrDrop::LocalStorageDead
| StorageDeadOrDrop::BoxedStorageDead => {
assert!(
Place::ty_from(&place.local, proj_base, *self.body, tcx)
Place::ty_from(place.local, proj_base, *self.body, tcx)
.ty
.is_box(),
"Drop of value behind a reference or raw pointer"
@ -1523,7 +1523,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

@ -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() {

View File

@ -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());
@ -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(
@ -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));

View File

@ -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(
@ -1740,7 +1740,7 @@ 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(
@ -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| {
@ -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)

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

@ -208,7 +208,7 @@ fn place_components_conflict<'tcx>(
// access cares about.
let proj_base = &borrow_place.projection[..access_place.projection.len() + i];
let base_ty = Place::ty_from(&borrow_local, proj_base, body, tcx).ty;
let base_ty = Place::ty_from(borrow_local, proj_base, body, tcx).ty;
match (elem, &base_ty.kind, access) {
(_, _, Shallow(Some(ArtificialField::ArrayLength)))
@ -329,7 +329,7 @@ fn place_projection_conflict<'tcx>(
debug!("place_element_conflict: DISJOINT-OR-EQ-FIELD");
Overlap::EqualOrDisjoint
} else {
let ty = Place::ty_from(&pi1_local, pi1_proj_base, body, tcx).ty;
let ty = Place::ty_from(pi1_local, pi1_proj_base, body, tcx).ty;
match ty.kind {
ty::Adt(def, _) if def.is_union() => {
// Different fields of a union, we are basically stuck.

View File

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

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];
@ -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 }

View File

@ -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,
);
@ -149,7 +149,7 @@ 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,

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,7 +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)
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) {

View File

@ -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);
}
}

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) {
@ -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() {
@ -589,7 +589,7 @@ 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,
@ -628,7 +628,7 @@ 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 };
}
@ -647,7 +647,7 @@ impl<'tcx> Validator<'_, 'tcx> {
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) {

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

@ -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,