mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Rollup merge of #91294 - cjgillot:process-elem, r=jackh726
Visit type in process_projection_elem. Instead of reimplementing it for each visitor.
This commit is contained in:
commit
dc78cd4c61
@ -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};
|
||||
|
||||
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user