@@ -151,29 +151,34 @@ impl<'a, 'tcx> PointerFinder<'a, 'tcx> {
151151 fn into_found_pointers ( self ) -> Vec < ( Place < ' tcx > , Ty < ' tcx > ) > {
152152 self . pointers
153153 }
154- }
155154
156- impl < ' a , ' tcx > Visitor < ' tcx > for PointerFinder < ' a , ' tcx > {
157- fn visit_place ( & mut self , place : & Place < ' tcx > , context : PlaceContext , location : Location ) {
155+ /// Whether or not we should visit a [Place] with [PlaceContext].
156+ ///
157+ /// We generally only visit Reads/Writes to a place and only Borrows if
158+ /// requested.
159+ fn should_visit_place ( & self , context : PlaceContext ) -> bool {
158160 match context {
159161 PlaceContext :: MutatingUse (
160162 MutatingUseContext :: Store
161163 | MutatingUseContext :: Call
162164 | MutatingUseContext :: Yield
163165 | MutatingUseContext :: Drop ,
164- ) => { }
166+ ) => true ,
165167 PlaceContext :: NonMutatingUse (
166168 NonMutatingUseContext :: Copy | NonMutatingUseContext :: Move ,
167- ) => { }
169+ ) => true ,
168170 PlaceContext :: MutatingUse ( MutatingUseContext :: Borrow )
169- | PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: SharedBorrow )
170- if matches ! ( self . borrow_check_mode, BorrowCheckMode :: IncludeBorrows ) => { }
171- _ => {
172- return ;
171+ | PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: SharedBorrow ) => {
172+ matches ! ( self . borrow_check_mode, BorrowCheckMode :: IncludeBorrows )
173173 }
174+ _ => false ,
174175 }
176+ }
177+ }
175178
176- if !place. is_indirect ( ) {
179+ impl < ' a , ' tcx > Visitor < ' tcx > for PointerFinder < ' a , ' tcx > {
180+ fn visit_place ( & mut self , place : & Place < ' tcx > , context : PlaceContext , location : Location ) {
181+ if !self . should_visit_place ( context) && !place. is_indirect ( ) {
177182 return ;
178183 }
179184
0 commit comments