@@ -291,9 +291,7 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
291291 // An item is allowed to constrain opaques declared within its own body (but not nested within
292292 // nested functions).
293293 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) )
297295 }
298296 }
299297 DefKind :: TyAlias | DefKind :: AssocTy => {
@@ -335,22 +333,24 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
335333 }
336334}
337335
336+ #[ instrument( level = "trace" , skip( tcx) , ret) ]
338337fn find_taits_declared_in_body ( tcx : TyCtxt < ' _ > , item : LocalDefId ) -> Vec < LocalDefId > {
339338 let body = tcx. hir ( ) . body ( tcx. hir ( ) . body_owned_by ( item) ) . value ;
340- #[ derive( Default , Debug ) ]
341- struct TaitInBodyFinder {
339+ struct TaitInBodyFinder < ' tcx > {
342340 /// Ids of type aliases found in the body
343341 type_aliases : Vec < LocalDefId > ,
342+ tcx : TyCtxt < ' tcx > ,
344343 }
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 ) ) ]
347346 fn visit_nested_item ( & mut self , id : rustc_hir:: ItemId ) {
348347 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+ }
350351 }
351352 }
352- let mut visitor = TaitInBodyFinder :: default ( ) ;
353- trace ! ( ?body) ;
353+ let mut visitor = TaitInBodyFinder { type_aliases : Default :: default ( ) , tcx } ;
354354 visitor. visit_expr ( body) ;
355355 visitor. type_aliases
356356}
0 commit comments