@@ -291,9 +291,7 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
291
291
// An item is allowed to constrain opaques declared within its own body (but not nested within
292
292
// nested functions).
293
293
for id in find_taits_declared_in_body ( tcx, item) {
294
- if let DefKind :: TyAlias = tcx. def_kind ( id) {
295
- collector. opaques . extend ( tcx. opaque_types_defined_by ( id) )
296
- }
294
+ collector. opaques . extend ( tcx. opaque_types_defined_by ( id) )
297
295
}
298
296
}
299
297
DefKind :: TyAlias | DefKind :: AssocTy => {
@@ -335,22 +333,24 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
335
333
}
336
334
}
337
335
336
+ #[ instrument( level = "trace" , skip( tcx) , ret) ]
338
337
fn find_taits_declared_in_body ( tcx : TyCtxt < ' _ > , item : LocalDefId ) -> Vec < LocalDefId > {
339
338
let body = tcx. hir ( ) . body ( tcx. hir ( ) . body_owned_by ( item) ) . value ;
340
- #[ derive( Default , Debug ) ]
341
- struct TaitInBodyFinder {
339
+ struct TaitInBodyFinder < ' tcx > {
342
340
/// Ids of type aliases found in the body
343
341
type_aliases : Vec < LocalDefId > ,
342
+ tcx : TyCtxt < ' tcx > ,
344
343
}
345
- impl < ' v > intravisit:: Visitor < ' v > for TaitInBodyFinder {
346
- #[ instrument( level = "trace" ) ]
344
+ impl < ' v > intravisit:: Visitor < ' v > for TaitInBodyFinder < ' _ > {
345
+ #[ instrument( level = "trace" , skip ( self ) ) ]
347
346
fn visit_nested_item ( & mut self , id : rustc_hir:: ItemId ) {
348
347
let id = id. owner_id . def_id ;
349
- self . type_aliases . push ( id) ;
348
+ if let DefKind :: TyAlias = self . tcx . def_kind ( id) {
349
+ self . type_aliases . push ( id) ;
350
+ }
350
351
}
351
352
}
352
- let mut visitor = TaitInBodyFinder :: default ( ) ;
353
- trace ! ( ?body) ;
353
+ let mut visitor = TaitInBodyFinder { type_aliases : Default :: default ( ) , tcx } ;
354
354
visitor. visit_expr ( body) ;
355
355
visitor. type_aliases
356
356
}
0 commit comments