@@ -84,7 +84,7 @@ pub trait DefIdVisitor<'tcx> {
84
84
fn skeleton ( & mut self ) -> DefIdVisitorSkeleton < ' _ , ' tcx , Self > {
85
85
DefIdVisitorSkeleton {
86
86
def_id_visitor : self ,
87
- visited_def_ids : Default :: default ( ) ,
87
+ visited_tys : Default :: default ( ) ,
88
88
dummy : Default :: default ( ) ,
89
89
}
90
90
}
@@ -104,7 +104,7 @@ pub trait DefIdVisitor<'tcx> {
104
104
105
105
pub struct DefIdVisitorSkeleton < ' v , ' tcx , V : ?Sized > {
106
106
def_id_visitor : & ' v mut V ,
107
- visited_def_ids : FxHashSet < DefId > ,
107
+ visited_tys : FxHashSet < Ty < ' tcx > > ,
108
108
dummy : PhantomData < TyCtxt < ' tcx > > ,
109
109
}
110
110
@@ -114,13 +114,11 @@ where
114
114
{
115
115
fn visit_trait ( & mut self , trait_ref : TraitRef < ' tcx > ) -> V :: Result {
116
116
let TraitRef { def_id, args, .. } = trait_ref;
117
- if self . visited_def_ids . insert ( def_id) {
118
- try_visit ! ( self . def_id_visitor. visit_def_id(
119
- def_id,
120
- "trait" ,
121
- & trait_ref. print_only_trait_path( )
122
- ) ) ;
123
- }
117
+ try_visit ! ( self . def_id_visitor. visit_def_id(
118
+ def_id,
119
+ "trait" ,
120
+ & trait_ref. print_only_trait_path( )
121
+ ) ) ;
124
122
if V :: SHALLOW { V :: Result :: output ( ) } else { args. visit_with ( self ) }
125
123
}
126
124
@@ -184,6 +182,9 @@ where
184
182
}
185
183
186
184
fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> Self :: Result {
185
+ if !self . visited_tys . insert ( ty) {
186
+ return V :: Result :: output ( ) ;
187
+ }
187
188
let tcx = self . def_id_visitor . tcx ( ) ;
188
189
// GenericArgs are not visited here because they are visited below
189
190
// in `super_visit_with`.
@@ -194,9 +195,7 @@ where
194
195
| ty:: Closure ( def_id, ..)
195
196
| ty:: CoroutineClosure ( def_id, ..)
196
197
| ty:: Coroutine ( def_id, ..) => {
197
- if self . visited_def_ids . insert ( def_id) {
198
- try_visit ! ( self . def_id_visitor. visit_def_id( def_id, "type" , & ty) ) ;
199
- }
198
+ try_visit ! ( self . def_id_visitor. visit_def_id( def_id, "type" , & ty) ) ;
200
199
if V :: SHALLOW {
201
200
return V :: Result :: output ( ) ;
202
201
}
@@ -227,17 +226,15 @@ where
227
226
return V :: Result :: output ( ) ;
228
227
}
229
228
230
- if self . visited_def_ids . insert ( data. def_id ) {
231
- try_visit ! ( self . def_id_visitor. visit_def_id(
232
- data. def_id,
233
- match kind {
234
- ty:: Inherent | ty:: Projection => "associated type" ,
235
- ty:: Free => "type alias" ,
236
- ty:: Opaque => unreachable!( ) ,
237
- } ,
238
- & LazyDefPathStr { def_id: data. def_id, tcx } ,
239
- ) ) ;
240
- }
229
+ try_visit ! ( self . def_id_visitor. visit_def_id(
230
+ data. def_id,
231
+ match kind {
232
+ ty:: Inherent | ty:: Projection => "associated type" ,
233
+ ty:: Free => "type alias" ,
234
+ ty:: Opaque => unreachable!( ) ,
235
+ } ,
236
+ & LazyDefPathStr { def_id: data. def_id, tcx } ,
237
+ ) ) ;
241
238
242
239
// This will also visit args if necessary, so we don't need to recurse.
243
240
return if V :: SHALLOW {
@@ -262,23 +259,18 @@ where
262
259
}
263
260
} ;
264
261
let ty:: ExistentialTraitRef { def_id, .. } = trait_ref;
265
- if self . visited_def_ids . insert ( def_id) {
266
- try_visit ! ( self . def_id_visitor. visit_def_id( def_id, "trait" , & trait_ref) ) ;
267
- }
262
+ try_visit ! ( self . def_id_visitor. visit_def_id( def_id, "trait" , & trait_ref) ) ;
268
263
}
269
264
}
270
265
ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, .. } ) => {
271
- // Skip repeated `Opaque`s to avoid infinite recursion.
272
- if self . visited_def_ids . insert ( def_id) {
273
- // The intent is to treat `impl Trait1 + Trait2` identically to
274
- // `dyn Trait1 + Trait2`. Therefore we ignore def-id of the opaque type itself
275
- // (it either has no visibility, or its visibility is insignificant, like
276
- // visibilities of type aliases) and recurse into bounds instead to go
277
- // through the trait list (default type visitor doesn't visit those traits).
278
- // All traits in the list are considered the "primary" part of the type
279
- // and are visited by shallow visitors.
280
- try_visit ! ( self . visit_clauses( tcx. explicit_item_bounds( def_id) . skip_binder( ) ) ) ;
281
- }
266
+ // The intent is to treat `impl Trait1 + Trait2` identically to
267
+ // `dyn Trait1 + Trait2`. Therefore we ignore def-id of the opaque type itself
268
+ // (it either has no visibility, or its visibility is insignificant, like
269
+ // visibilities of type aliases) and recurse into bounds instead to go
270
+ // through the trait list (default type visitor doesn't visit those traits).
271
+ // All traits in the list are considered the "primary" part of the type
272
+ // and are visited by shallow visitors.
273
+ try_visit ! ( self . visit_clauses( tcx. explicit_item_bounds( def_id) . skip_binder( ) ) ) ;
282
274
}
283
275
// These types don't have their own def-ids (but may have subcomponents
284
276
// with def-ids that should be visited recursively).
0 commit comments