From cc527464bb3c891e062c58cd954c63b556d059ec Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 5 Jun 2019 19:56:11 +0200 Subject: [PATCH] Make visit_place traverse place and have visit_place_base and visit_projection doing the real work --- src/librustc/mir/visit.rs | 60 +++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index dd33fae0d61..2f19f591830 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -151,17 +151,17 @@ macro_rules! make_mir_visitor { self.super_place(place, context, location); } - fn visit_projection(&mut self, - place: & $($mutability)? Projection<'tcx>, + fn visit_place_base(&mut self, + place_base: & $($mutability)? PlaceBase<'tcx>, context: PlaceContext, location: Location) { - self.super_projection(place, context, location); + self.super_place_base(place_base, context, location); } - fn visit_projection_elem(&mut self, - place: & $($mutability)? PlaceElem<'tcx>, - location: Location) { - self.super_projection_elem(place, location); + fn visit_projection(&mut self, + place: & $($mutability)? Projection<'tcx>, + location: Location) { + self.super_projection(place, location); } fn visit_constant(&mut self, @@ -676,36 +676,40 @@ macro_rules! make_mir_visitor { context: PlaceContext, location: Location) { match place { - Place::Base(PlaceBase::Local(local)) => { - self.visit_local(local, context, location); - } - Place::Base(PlaceBase::Static(box Static { kind: _, ty })) => { - self.visit_ty(& $($mutability)? *ty, TyContext::Location(location)); + Place::Base(place_base) => { + self.visit_place_base(place_base, context, location); } Place::Projection(proj) => { - self.visit_projection(proj, context, location); + let context = if context.is_mutating_use() { + PlaceContext::MutatingUse(MutatingUseContext::Projection) + } else { + PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) + }; + + self.visit_place(& $($mutability)? proj.base, context, location); + self.visit_projection(proj, location); + } + } + } + + fn super_place_base(&mut self, + place_base: & $($mutability)? PlaceBase<'tcx>, + context: PlaceContext, + location: Location) { + match place_base { + PlaceBase::Local(local) => { + self.visit_local(local, context, location); + } + PlaceBase::Static(box Static { kind: _, ty }) => { + self.visit_ty(& $($mutability)? *ty, TyContext::Location(location)); } } } fn super_projection(&mut self, proj: & $($mutability)? Projection<'tcx>, - context: PlaceContext, location: Location) { - let Projection { base, elem } = proj; - let context = if context.is_mutating_use() { - PlaceContext::MutatingUse(MutatingUseContext::Projection) - } else { - PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) - }; - self.visit_place(base, context, location); - self.visit_projection_elem(elem, location); - } - - fn super_projection_elem(&mut self, - proj: & $($mutability)? PlaceElem<'tcx>, - location: Location) { - match proj { + match & $($mutability)? proj.elem { ProjectionElem::Deref => { } ProjectionElem::Subslice { from: _, to: _ } => {