Skip to content

Commit

Permalink
Place::ty_from takes local by value
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Jan 23, 2020
1 parent e5b1837 commit e51b5a4
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 47 deletions.
6 changes: 3 additions & 3 deletions src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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)
})
}
Expand All @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 @@ -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)
}
}
10 changes: 5 additions & 5 deletions src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, _) => {
Expand Down Expand Up @@ -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));
}
_ => {}
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,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(
Expand Down Expand Up @@ -1742,7 +1742,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(
Expand Down Expand Up @@ -1846,7 +1846,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| {
Expand Down Expand Up @@ -2060,7 +2060,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 {
Expand Down Expand Up @@ -2194,7 +2194,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)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/place_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/places_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/prefixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/dataflow/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -492,7 +492,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 }
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -258,7 +258,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",
Expand Down Expand Up @@ -412,7 +412,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) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/instcombine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Loading

0 comments on commit e51b5a4

Please sign in to comment.