@@ -838,7 +838,7 @@ macro_rules! make_mir_visitor {
838838}
839839
840840macro_rules! visit_place_fns {
841- ( mut ) => (
841+ ( mut ) => {
842842 fn tcx<' a>( & ' a self ) -> TyCtxt <' tcx>;
843843
844844 fn super_place(
@@ -849,20 +849,21 @@ macro_rules! visit_place_fns {
849849 ) {
850850 self . visit_place_base( & mut place. local, context, location) ;
851851
852- if let Some ( new_projection) = self . process_projection( & place. projection) {
852+ if let Some ( new_projection) = self . process_projection( & place. projection, location ) {
853853 place. projection = self . tcx( ) . intern_place_elems( & new_projection) ;
854854 }
855855 }
856856
857857 fn process_projection(
858858 & mut self ,
859859 projection: & ' a [ PlaceElem <' tcx>] ,
860+ location: Location ,
860861 ) -> Option <Vec <PlaceElem <' tcx>>> {
861862 let mut projection = Cow :: Borrowed ( projection) ;
862863
863864 for i in 0 ..projection. len( ) {
864865 if let Some ( elem) = projection. get( i) {
865- if let Some ( elem) = self . process_projection_elem( elem) {
866+ if let Some ( elem) = self . process_projection_elem( elem, location ) {
866867 // This converts the borrowed projection into `Cow::Owned(_)` and returns a
867868 // clone of the projection so we can mutate and reintern later.
868869 let vec = projection. to_mut( ) ;
@@ -879,13 +880,30 @@ macro_rules! visit_place_fns {
879880
880881 fn process_projection_elem(
881882 & mut self ,
882- _elem: & PlaceElem <' tcx>,
883+ elem: & PlaceElem <' tcx>,
884+ location: Location ,
883885 ) -> Option <PlaceElem <' tcx>> {
884- None
886+ match elem {
887+ PlaceElem :: Index ( local) => {
888+ let mut new_local = * local;
889+ self . visit_local(
890+ & mut new_local,
891+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Copy ) ,
892+ location,
893+ ) ;
894+
895+ if new_local == * local { None } else { Some ( PlaceElem :: Index ( new_local) ) }
896+ }
897+ PlaceElem :: Deref
898+ | PlaceElem :: Field ( ..)
899+ | PlaceElem :: ConstantIndex { .. }
900+ | PlaceElem :: Subslice { .. }
901+ | PlaceElem :: Downcast ( ..) => None ,
902+ }
885903 }
886- ) ;
904+ } ;
887905
888- ( ) => (
906+ ( ) => {
889907 fn visit_projection(
890908 & mut self ,
891909 local: Local ,
@@ -907,12 +925,7 @@ macro_rules! visit_place_fns {
907925 self . super_projection_elem( local, proj_base, elem, context, location) ;
908926 }
909927
910- fn super_place(
911- & mut self ,
912- place: & Place <' tcx>,
913- context: PlaceContext ,
914- location: Location ,
915- ) {
928+ fn super_place( & mut self , place: & Place <' tcx>, context: PlaceContext , location: Location ) {
916929 let mut context = context;
917930
918931 if !place. projection. is_empty( ) {
@@ -925,10 +938,7 @@ macro_rules! visit_place_fns {
925938
926939 self . visit_place_base( & place. local, context, location) ;
927940
928- self . visit_projection( place. local,
929- & place. projection,
930- context,
931- location) ;
941+ self . visit_projection( place. local, & place. projection, context, location) ;
932942 }
933943
934944 fn super_projection(
@@ -961,19 +971,16 @@ macro_rules! visit_place_fns {
961971 self . visit_local(
962972 local,
963973 PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Copy ) ,
964- location
974+ location,
965975 ) ;
966976 }
967- ProjectionElem :: Deref |
968- ProjectionElem :: Subslice { from: _, to: _, from_end: _ } |
969- ProjectionElem :: ConstantIndex { offset: _,
970- min_length: _,
971- from_end: _ } |
972- ProjectionElem :: Downcast ( _, _) => {
973- }
977+ ProjectionElem :: Deref
978+ | ProjectionElem :: Subslice { from: _, to: _, from_end: _ }
979+ | ProjectionElem :: ConstantIndex { offset: _, min_length: _, from_end: _ }
980+ | ProjectionElem :: Downcast ( _, _) => { }
974981 }
975982 }
976- ) ;
983+ } ;
977984}
978985
979986make_mir_visitor ! ( Visitor , ) ;
0 commit comments