Skip to content

Commit 7fa3425

Browse files
committed
Setup a different visit place set of methods for mutable and immutable visitors
In particular, use a blank visit_place for mutable visitor to be sure, non modified visitors are not trying to mutating place.
1 parent 4f2a110 commit 7fa3425

File tree

1 file changed

+103
-77
lines changed

1 file changed

+103
-77
lines changed

src/librustc/mir/visit.rs

Lines changed: 103 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,7 @@ macro_rules! make_mir_visitor {
158158
self.super_place_base(base, context, location);
159159
}
160160

161-
fn visit_projection(&mut self,
162-
base: & $($mutability)? PlaceBase<'tcx>,
163-
projection: & $($mutability)? [PlaceElem<'tcx>],
164-
context: PlaceContext,
165-
location: Location) {
166-
self.super_projection(base, projection, context, location);
167-
}
168-
169-
fn visit_projection_elem(&mut self,
170-
base: & $($mutability)? PlaceBase<'tcx>,
171-
proj_base: & $($mutability)? [PlaceElem<'tcx>],
172-
elem: & $($mutability)? PlaceElem<'tcx>,
173-
context: PlaceContext,
174-
location: Location) {
175-
self.super_projection_elem(base, proj_base, elem, context, location);
176-
}
161+
visit_place_fns!($($mutability)?);
177162

178163
fn visit_constant(&mut self,
179164
constant: & $($mutability)? Constant<'tcx>,
@@ -681,28 +666,6 @@ macro_rules! make_mir_visitor {
681666
);
682667
}
683668

684-
fn super_place(&mut self,
685-
place: & $($mutability)? Place<'tcx>,
686-
context: PlaceContext,
687-
location: Location) {
688-
let mut context = context;
689-
690-
if !place.projection.is_empty() {
691-
context = if context.is_mutating_use() {
692-
PlaceContext::MutatingUse(MutatingUseContext::Projection)
693-
} else {
694-
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
695-
};
696-
}
697-
698-
self.visit_place_base(& $($mutability)? place.base, context, location);
699-
700-
self.visit_projection(& $($mutability)? place.base,
701-
& $($mutability)? place.projection,
702-
context,
703-
location);
704-
}
705-
706669
fn super_place_base(&mut self,
707670
place_base: & $($mutability)? PlaceBase<'tcx>,
708671
context: PlaceContext,
@@ -717,45 +680,6 @@ macro_rules! make_mir_visitor {
717680
}
718681
}
719682

720-
fn super_projection(&mut self,
721-
base: & $($mutability)? PlaceBase<'tcx>,
722-
projection: & $($mutability)? [PlaceElem<'tcx>],
723-
context: PlaceContext,
724-
location: Location) {
725-
let mut cursor = projection;
726-
while let [proj_base @ .., elem] = cursor {
727-
cursor = proj_base;
728-
self.visit_projection_elem(base, cursor, elem, context, location);
729-
}
730-
}
731-
732-
fn super_projection_elem(&mut self,
733-
_base: & $($mutability)? PlaceBase<'tcx>,
734-
_proj_base: & $($mutability)? [PlaceElem<'tcx>],
735-
elem: & $($mutability)? PlaceElem<'tcx>,
736-
_context: PlaceContext,
737-
location: Location) {
738-
match elem {
739-
ProjectionElem::Field(_field, ty) => {
740-
self.visit_ty(ty, TyContext::Location(location));
741-
}
742-
ProjectionElem::Index(local) => {
743-
self.visit_local(
744-
local,
745-
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
746-
location
747-
);
748-
}
749-
ProjectionElem::Deref |
750-
ProjectionElem::Subslice { from: _, to: _ } |
751-
ProjectionElem::ConstantIndex { offset: _,
752-
min_length: _,
753-
from_end: _ } |
754-
ProjectionElem::Downcast(_, _) => {
755-
}
756-
}
757-
}
758-
759683
fn super_local_decl(&mut self,
760684
local: Local,
761685
local_decl: & $($mutability)? LocalDecl<'tcx>) {
@@ -858,6 +782,108 @@ macro_rules! make_mir_visitor {
858782
}
859783
}
860784

785+
macro_rules! visit_place_fns {
786+
(mut) => (
787+
fn super_place(
788+
&mut self,
789+
_place: &mut Place<'tcx>,
790+
_context: PlaceContext,
791+
_location: Location,
792+
) {
793+
}
794+
);
795+
796+
() => (
797+
fn visit_projection(
798+
&mut self,
799+
base: &PlaceBase<'tcx>,
800+
projection: &[PlaceElem<'tcx>],
801+
context: PlaceContext,
802+
location: Location,
803+
) {
804+
self.super_projection(base, projection, context, location);
805+
}
806+
807+
fn visit_projection_elem(
808+
&mut self,
809+
base: &PlaceBase<'tcx>,
810+
proj_base: &[PlaceElem<'tcx>],
811+
elem: &PlaceElem<'tcx>,
812+
context: PlaceContext,
813+
location: Location,
814+
) {
815+
self.super_projection_elem(base, proj_base, elem, context, location);
816+
}
817+
818+
fn super_place(
819+
&mut self,
820+
place: &Place<'tcx>,
821+
context: PlaceContext,
822+
location: Location,
823+
) {
824+
let mut context = context;
825+
826+
if !place.projection.is_empty() {
827+
context = if context.is_mutating_use() {
828+
PlaceContext::MutatingUse(MutatingUseContext::Projection)
829+
} else {
830+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
831+
};
832+
}
833+
834+
self.visit_place_base(&place.base, context, location);
835+
836+
self.visit_projection(&place.base,
837+
&place.projection,
838+
context,
839+
location);
840+
}
841+
842+
fn super_projection(
843+
&mut self,
844+
base: &PlaceBase<'tcx>,
845+
projection: &[PlaceElem<'tcx>],
846+
context: PlaceContext,
847+
location: Location,
848+
) {
849+
let mut cursor = projection;
850+
while let [proj_base @ .., elem] = cursor {
851+
cursor = proj_base;
852+
self.visit_projection_elem(base, cursor, elem, context, location);
853+
}
854+
}
855+
856+
fn super_projection_elem(
857+
&mut self,
858+
_base: &PlaceBase<'tcx>,
859+
_proj_base: &[PlaceElem<'tcx>],
860+
elem: &PlaceElem<'tcx>,
861+
_context: PlaceContext,
862+
location: Location,
863+
) {
864+
match elem {
865+
ProjectionElem::Field(_field, ty) => {
866+
self.visit_ty(ty, TyContext::Location(location));
867+
}
868+
ProjectionElem::Index(local) => {
869+
self.visit_local(
870+
local,
871+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
872+
location
873+
);
874+
}
875+
ProjectionElem::Deref |
876+
ProjectionElem::Subslice { from: _, to: _ } |
877+
ProjectionElem::ConstantIndex { offset: _,
878+
min_length: _,
879+
from_end: _ } |
880+
ProjectionElem::Downcast(_, _) => {
881+
}
882+
}
883+
}
884+
);
885+
}
886+
861887
make_mir_visitor!(Visitor,);
862888
make_mir_visitor!(MutVisitor,mut);
863889

0 commit comments

Comments
 (0)