@@ -182,9 +182,6 @@ where
182
182
}
183
183
184
184
fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> Self :: Result {
185
- if !self . visited_tys . insert ( ty) {
186
- return V :: Result :: output ( ) ;
187
- }
188
185
let tcx = self . def_id_visitor . tcx ( ) ;
189
186
// GenericArgs are not visited here because they are visited below
190
187
// in `super_visit_with`.
@@ -195,6 +192,9 @@ where
195
192
| ty:: Closure ( def_id, ..)
196
193
| ty:: CoroutineClosure ( def_id, ..)
197
194
| ty:: Coroutine ( def_id, ..) => {
195
+ if !self . visited_tys . insert ( ty) {
196
+ return V :: Result :: output ( ) ;
197
+ }
198
198
try_visit ! ( self . def_id_visitor. visit_def_id( def_id, "type" , & ty) ) ;
199
199
if V :: SHALLOW {
200
200
return V :: Result :: output ( ) ;
@@ -217,6 +217,9 @@ where
217
217
}
218
218
}
219
219
ty:: Alias ( kind @ ( ty:: Inherent | ty:: Free | ty:: Projection ) , data) => {
220
+ if !self . visited_tys . insert ( ty) {
221
+ return V :: Result :: output ( ) ;
222
+ }
220
223
if self . def_id_visitor . skip_assoc_tys ( ) {
221
224
// Visitors searching for minimal visibility/reachability want to
222
225
// conservatively approximate associated types like `Type::Alias`
@@ -248,6 +251,9 @@ where
248
251
} ;
249
252
}
250
253
ty:: Dynamic ( predicates, ..) => {
254
+ if !self . visited_tys . insert ( ty) {
255
+ return V :: Result :: output ( ) ;
256
+ }
251
257
// All traits in the list are considered the "primary" part of the type
252
258
// and are visited by shallow visitors.
253
259
for predicate in predicates {
@@ -263,6 +269,9 @@ where
263
269
}
264
270
}
265
271
ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, .. } ) => {
272
+ if !self . visited_tys . insert ( ty) {
273
+ return V :: Result :: output ( ) ;
274
+ }
266
275
// The intent is to treat `impl Trait1 + Trait2` identically to
267
276
// `dyn Trait1 + Trait2`. Therefore we ignore def-id of the opaque type itself
268
277
// (it either has no visibility, or its visibility is insignificant, like
@@ -272,27 +281,33 @@ where
272
281
// and are visited by shallow visitors.
273
282
try_visit ! ( self . visit_clauses( tcx. explicit_item_bounds( def_id) . skip_binder( ) ) ) ;
274
283
}
275
- // These types don't have their own def-ids (but may have subcomponents
276
- // with def-ids that should be visited recursively).
284
+ // These types have neither their own def-ids nor subcomponents.
277
285
ty:: Bool
278
286
| ty:: Char
279
287
| ty:: Int ( ..)
280
288
| ty:: Uint ( ..)
281
289
| ty:: Float ( ..)
282
290
| ty:: Str
283
291
| ty:: Never
284
- | ty:: Array ( ..)
292
+ | ty:: Bound ( ..)
293
+ | ty:: Param ( ..) => return V :: Result :: output ( ) ,
294
+
295
+ // These types don't have their own def-ids (but may have subcomponents
296
+ // with def-ids that should be visited recursively).
297
+ ty:: Array ( ..)
285
298
| ty:: Slice ( ..)
286
299
| ty:: Tuple ( ..)
287
300
| ty:: RawPtr ( ..)
288
301
| ty:: Ref ( ..)
289
302
| ty:: Pat ( ..)
290
303
| ty:: FnPtr ( ..)
291
304
| ty:: UnsafeBinder ( _)
292
- | ty:: Param ( ..)
293
- | ty:: Bound ( ..)
294
305
| ty:: Error ( _)
295
- | ty:: CoroutineWitness ( ..) => { }
306
+ | ty:: CoroutineWitness ( ..) => {
307
+ if !self . visited_tys . insert ( ty) {
308
+ return V :: Result :: output ( ) ;
309
+ }
310
+ }
296
311
ty:: Placeholder ( ..) | ty:: Infer ( ..) => {
297
312
bug ! ( "unexpected type: {:?}" , ty)
298
313
}
0 commit comments