Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 33 additions & 26 deletions src/librustc_middle/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ macro_rules! make_mir_visitor {
}

macro_rules! visit_place_fns {
(mut) => (
(mut) => {
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;

fn super_place(
Expand All @@ -849,20 +849,21 @@ macro_rules! visit_place_fns {
) {
self.visit_place_base(&mut place.local, context, location);

if let Some(new_projection) = self.process_projection(&place.projection) {
if let Some(new_projection) = self.process_projection(&place.projection, location) {
place.projection = self.tcx().intern_place_elems(&new_projection);
}
}

fn process_projection(
&mut self,
projection: &'a [PlaceElem<'tcx>],
location: Location,
) -> Option<Vec<PlaceElem<'tcx>>> {
let mut projection = Cow::Borrowed(projection);

for i in 0..projection.len() {
if let Some(elem) = projection.get(i) {
if let Some(elem) = self.process_projection_elem(elem) {
if let Some(elem) = self.process_projection_elem(elem, location) {
// This converts the borrowed projection into `Cow::Owned(_)` and returns a
// clone of the projection so we can mutate and reintern later.
let vec = projection.to_mut();
Expand All @@ -879,13 +880,30 @@ macro_rules! visit_place_fns {

fn process_projection_elem(
&mut self,
_elem: &PlaceElem<'tcx>,
elem: &PlaceElem<'tcx>,
location: Location,
) -> Option<PlaceElem<'tcx>> {
None
match elem {
PlaceElem::Index(local) => {
let mut new_local = *local;
self.visit_local(
&mut new_local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location,
);

if new_local == *local { None } else { Some(PlaceElem::Index(new_local)) }
}
PlaceElem::Deref
| PlaceElem::Field(..)
| PlaceElem::ConstantIndex { .. }
| PlaceElem::Subslice { .. }
| PlaceElem::Downcast(..) => None,
}
}
);
};

() => (
() => {
fn visit_projection(
&mut self,
local: Local,
Expand All @@ -907,12 +925,7 @@ macro_rules! visit_place_fns {
self.super_projection_elem(local, proj_base, elem, context, location);
}

fn super_place(
&mut self,
place: &Place<'tcx>,
context: PlaceContext,
location: Location,
) {
fn super_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
let mut context = context;

if !place.projection.is_empty() {
Expand All @@ -925,10 +938,7 @@ macro_rules! visit_place_fns {

self.visit_place_base(&place.local, context, location);

self.visit_projection(place.local,
&place.projection,
context,
location);
self.visit_projection(place.local, &place.projection, context, location);
}

fn super_projection(
Expand Down Expand Up @@ -961,19 +971,16 @@ macro_rules! visit_place_fns {
self.visit_local(
local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location
location,
);
}
ProjectionElem::Deref |
ProjectionElem::Subslice { from: _, to: _, from_end: _ } |
ProjectionElem::ConstantIndex { offset: _,
min_length: _,
from_end: _ } |
ProjectionElem::Downcast(_, _) => {
}
ProjectionElem::Deref
| ProjectionElem::Subslice { from: _, to: _, from_end: _ }
| ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ }
| ProjectionElem::Downcast(_, _) => {}
}
}
);
};
}

make_mir_visitor!(Visitor,);
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_mir/borrow_check/renumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> {
debug!("visit_ty: ty={:?}", ty);
}

fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
fn process_projection_elem(
&mut self,
elem: &PlaceElem<'tcx>,
_: Location,
) -> Option<PlaceElem<'tcx>> {
if let PlaceElem::Field(field, ty) = elem {
let new_ty = self.renumber_regions(ty);

Expand Down
7 changes: 0 additions & 7 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ impl<'tcx> MutVisitor<'tcx> for RenameLocalVisitor<'tcx> {
*local = self.to;
}
}

fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) if *local == self.from => Some(PlaceElem::Index(self.to)),
_ => None,
}
}
}

struct DerefArgVisitor<'tcx> {
Expand Down
12 changes: 0 additions & 12 deletions src/librustc_mir/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,18 +706,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
self.super_place(place, context, location)
}

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

if new_local != *local {
return Some(PlaceElem::Index(new_local));
}
}

None
}

fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) {
self.in_cleanup_block = data.is_cleanup;
self.super_basic_block_data(block, data);
Expand Down
9 changes: 0 additions & 9 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,15 +1036,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
*local = self.promote_temp(*local);
}
}

fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) if self.is_temp_kind(*local) => {
Some(PlaceElem::Index(self.promote_temp(*local)))
}
_ => None,
}
}
}

pub fn promote_candidates<'tcx>(
Expand Down
7 changes: 0 additions & 7 deletions src/librustc_mir/transform/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,4 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater<'tcx> {
fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) {
*l = self.map[*l].unwrap();
}

fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) => Some(PlaceElem::Index(self.map[*local].unwrap())),
_ => None,
}
}
}
13 changes: 1 addition & 12 deletions src/librustc_mir/util/def_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
use rustc_index::vec::IndexVec;
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
use rustc_middle::mir::{
Body, BodyAndCache, Local, Location, PlaceElem, ReadOnlyBodyAndCache, VarDebugInfo,
};
use rustc_middle::mir::{Body, BodyAndCache, Local, Location, ReadOnlyBodyAndCache, VarDebugInfo};
use rustc_middle::ty::TyCtxt;
use std::mem;

Expand Down Expand Up @@ -157,13 +155,4 @@ impl MutVisitor<'tcx> for MutateUseVisitor<'tcx> {
*local = self.new_local;
}
}

fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) if *local == self.query => {
Some(PlaceElem::Index(self.new_local))
}
_ => None,
}
}
}