Skip to content

Commit dc78cd4

Browse files
authored
Rollup merge of #91294 - cjgillot:process-elem, r=jackh726
Visit type in process_projection_elem. Instead of reimplementing it for each visitor.
2 parents 207c80f + 29b30a9 commit dc78cd4

File tree

4 files changed

+6
-60
lines changed

4 files changed

+6
-60
lines changed

compiler/rustc_borrowck/src/renumber.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_index::vec::IndexVec;
22
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
33
use rustc_middle::mir::visit::{MutVisitor, TyContext};
4-
use rustc_middle::mir::{Body, Location, PlaceElem, Promoted};
4+
use rustc_middle::mir::{Body, Location, Promoted};
55
use rustc_middle::ty::subst::SubstsRef;
66
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
77

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

65-
fn process_projection_elem(
66-
&mut self,
67-
elem: PlaceElem<'tcx>,
68-
_: Location,
69-
) -> Option<PlaceElem<'tcx>> {
70-
if let PlaceElem::Field(field, ty) = elem {
71-
let new_ty = self.renumber_regions(ty);
72-
73-
if new_ty != ty {
74-
return Some(PlaceElem::Field(field, new_ty));
75-
}
76-
}
77-
78-
None
79-
}
80-
8165
#[instrument(skip(self), level = "debug")]
8266
fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
8367
*substs = self.renumber_regions(*substs);

compiler/rustc_middle/src/mir/visit.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,12 @@ macro_rules! visit_place_fns {
10041004

10051005
if new_local == local { None } else { Some(PlaceElem::Index(new_local)) }
10061006
}
1007+
PlaceElem::Field(field, ty) => {
1008+
let mut new_ty = ty;
1009+
self.visit_ty(&mut new_ty, TyContext::Location(location));
1010+
if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
1011+
}
10071012
PlaceElem::Deref
1008-
| PlaceElem::Field(..)
10091013
| PlaceElem::ConstantIndex { .. }
10101014
| PlaceElem::Subslice { .. }
10111015
| PlaceElem::Downcast(..) => None,

compiler/rustc_mir_transform/src/dest_prop.rs

-22
Original file line numberDiff line numberDiff line change
@@ -316,28 +316,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
316316
}
317317
}
318318

319-
fn process_projection_elem(
320-
&mut self,
321-
elem: PlaceElem<'tcx>,
322-
_: Location,
323-
) -> Option<PlaceElem<'tcx>> {
324-
match elem {
325-
PlaceElem::Index(local) => {
326-
if let Some(replacement) = self.replacements.for_src(local) {
327-
bug!(
328-
"cannot replace {:?} with {:?} in index projection {:?}",
329-
local,
330-
replacement,
331-
elem,
332-
);
333-
} else {
334-
None
335-
}
336-
}
337-
_ => None,
338-
}
339-
}
340-
341319
fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) {
342320
if let Some(replacement) = self.replacements.for_src(place.local) {
343321
// Rebase `place`s projections onto `replacement`'s.

compiler/rustc_mir_transform/src/reveal_all.rs

-20
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,4 @@ impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
3535
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) {
3636
*ty = self.tcx.normalize_erasing_regions(self.param_env, ty);
3737
}
38-
39-
#[inline]
40-
fn process_projection_elem(
41-
&mut self,
42-
elem: PlaceElem<'tcx>,
43-
_: Location,
44-
) -> Option<PlaceElem<'tcx>> {
45-
match elem {
46-
PlaceElem::Field(field, ty) => {
47-
let new_ty = self.tcx.normalize_erasing_regions(self.param_env, ty);
48-
if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
49-
}
50-
// None of those contain a Ty.
51-
PlaceElem::Index(..)
52-
| PlaceElem::Deref
53-
| PlaceElem::ConstantIndex { .. }
54-
| PlaceElem::Subslice { .. }
55-
| PlaceElem::Downcast(..) => None,
56-
}
57-
}
5838
}

0 commit comments

Comments
 (0)