@@ -838,7 +838,7 @@ macro_rules! make_mir_visitor {
838
838
}
839
839
840
840
macro_rules! visit_place_fns {
841
- ( mut ) => (
841
+ ( mut ) => {
842
842
fn tcx<' a>( & ' a self ) -> TyCtxt <' tcx>;
843
843
844
844
fn super_place(
@@ -849,20 +849,21 @@ macro_rules! visit_place_fns {
849
849
) {
850
850
self . visit_place_base( & mut place. local, context, location) ;
851
851
852
- if let Some ( new_projection) = self . process_projection( & place. projection) {
852
+ if let Some ( new_projection) = self . process_projection( & place. projection, location ) {
853
853
place. projection = self . tcx( ) . intern_place_elems( & new_projection) ;
854
854
}
855
855
}
856
856
857
857
fn process_projection(
858
858
& mut self ,
859
859
projection: & ' a [ PlaceElem <' tcx>] ,
860
+ location: Location ,
860
861
) -> Option <Vec <PlaceElem <' tcx>>> {
861
862
let mut projection = Cow :: Borrowed ( projection) ;
862
863
863
864
for i in 0 ..projection. len( ) {
864
865
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 ) {
866
867
// This converts the borrowed projection into `Cow::Owned(_)` and returns a
867
868
// clone of the projection so we can mutate and reintern later.
868
869
let vec = projection. to_mut( ) ;
@@ -879,13 +880,30 @@ macro_rules! visit_place_fns {
879
880
880
881
fn process_projection_elem(
881
882
& mut self ,
882
- _elem: & PlaceElem <' tcx>,
883
+ elem: & PlaceElem <' tcx>,
884
+ location: Location ,
883
885
) -> 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
+ }
885
903
}
886
- ) ;
904
+ } ;
887
905
888
- ( ) => (
906
+ ( ) => {
889
907
fn visit_projection(
890
908
& mut self ,
891
909
local: Local ,
@@ -907,12 +925,7 @@ macro_rules! visit_place_fns {
907
925
self . super_projection_elem( local, proj_base, elem, context, location) ;
908
926
}
909
927
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 ) {
916
929
let mut context = context;
917
930
918
931
if !place. projection. is_empty( ) {
@@ -925,10 +938,7 @@ macro_rules! visit_place_fns {
925
938
926
939
self . visit_place_base( & place. local, context, location) ;
927
940
928
- self . visit_projection( place. local,
929
- & place. projection,
930
- context,
931
- location) ;
941
+ self . visit_projection( place. local, & place. projection, context, location) ;
932
942
}
933
943
934
944
fn super_projection(
@@ -961,19 +971,16 @@ macro_rules! visit_place_fns {
961
971
self . visit_local(
962
972
local,
963
973
PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Copy ) ,
964
- location
974
+ location,
965
975
) ;
966
976
}
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 ( _, _) => { }
974
981
}
975
982
}
976
- ) ;
983
+ } ;
977
984
}
978
985
979
986
make_mir_visitor ! ( Visitor , ) ;
0 commit comments