Skip to content

Commit

Permalink
Rollup merge of rust-lang#91294 - cjgillot:process-elem, r=jackh726
Browse files Browse the repository at this point in the history
Visit type in process_projection_elem.

Instead of reimplementing it for each visitor.
  • Loading branch information
matthiaskrgr authored Nov 30, 2021
2 parents 207c80f + 29b30a9 commit dc78cd4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 60 deletions.
18 changes: 1 addition & 17 deletions compiler/rustc_borrowck/src/renumber.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_index::vec::IndexVec;
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
use rustc_middle::mir::visit::{MutVisitor, TyContext};
use rustc_middle::mir::{Body, Location, PlaceElem, Promoted};
use rustc_middle::mir::{Body, Location, Promoted};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};

Expand Down Expand Up @@ -62,22 +62,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
debug!(?ty);
}

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

if new_ty != ty {
return Some(PlaceElem::Field(field, new_ty));
}
}

None
}

#[instrument(skip(self), level = "debug")]
fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
*substs = self.renumber_regions(*substs);
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,12 @@ macro_rules! visit_place_fns {

if new_local == local { None } else { Some(PlaceElem::Index(new_local)) }
}
PlaceElem::Field(field, ty) => {
let mut new_ty = ty;
self.visit_ty(&mut new_ty, TyContext::Location(location));
if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
}
PlaceElem::Deref
| PlaceElem::Field(..)
| PlaceElem::ConstantIndex { .. }
| PlaceElem::Subslice { .. }
| PlaceElem::Downcast(..) => None,
Expand Down
22 changes: 0 additions & 22 deletions compiler/rustc_mir_transform/src/dest_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,28 +316,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
}
}

fn process_projection_elem(
&mut self,
elem: PlaceElem<'tcx>,
_: Location,
) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) => {
if let Some(replacement) = self.replacements.for_src(local) {
bug!(
"cannot replace {:?} with {:?} in index projection {:?}",
local,
replacement,
elem,
);
} else {
None
}
}
_ => None,
}
}

fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) {
if let Some(replacement) = self.replacements.for_src(place.local) {
// Rebase `place`s projections onto `replacement`'s.
Expand Down
20 changes: 0 additions & 20 deletions compiler/rustc_mir_transform/src/reveal_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,4 @@ impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) {
*ty = self.tcx.normalize_erasing_regions(self.param_env, ty);
}

#[inline]
fn process_projection_elem(
&mut self,
elem: PlaceElem<'tcx>,
_: Location,
) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Field(field, ty) => {
let new_ty = self.tcx.normalize_erasing_regions(self.param_env, ty);
if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
}
// None of those contain a Ty.
PlaceElem::Index(..)
| PlaceElem::Deref
| PlaceElem::ConstantIndex { .. }
| PlaceElem::Subslice { .. }
| PlaceElem::Downcast(..) => None,
}
}
}

0 comments on commit dc78cd4

Please sign in to comment.