@@ -103,31 +103,26 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
103103 self . tcx . predicates_of ( self . item ) . instantiate_identity ( self . tcx ) . visit_with ( self ) ;
104104 // An item is allowed to constrain opaques declared within its own body (but not nested within
105105 // nested functions).
106- for id in self . find_taits_declared_in_body ( ) {
107- self . opaques . extend ( self . tcx . opaque_types_defined_by ( id) )
108- }
106+ self . collect_taits_declared_in_body ( ) ;
109107 }
110108
111- #[ instrument( level = "trace" , skip( self ) , ret ) ]
112- fn find_taits_declared_in_body ( & self ) -> Vec < LocalDefId > {
109+ #[ instrument( level = "trace" , skip( self ) ) ]
110+ fn collect_taits_declared_in_body ( & mut self ) {
113111 let body = self . tcx . hir ( ) . body ( self . tcx . hir ( ) . body_owned_by ( self . item ) ) . value ;
114- struct TaitInBodyFinder < ' tcx > {
115- /// Ids of type aliases found in the body
116- type_aliases : Vec < LocalDefId > ,
117- tcx : TyCtxt < ' tcx > ,
112+ struct TaitInBodyFinder < ' a , ' tcx > {
113+ collector : & ' a mut OpaqueTypeCollector < ' tcx > ,
118114 }
119- impl < ' v > intravisit:: Visitor < ' v > for TaitInBodyFinder < ' _ > {
115+ impl < ' v > intravisit:: Visitor < ' v > for TaitInBodyFinder < ' _ , ' _ > {
120116 #[ instrument( level = "trace" , skip( self ) ) ]
121117 fn visit_nested_item ( & mut self , id : rustc_hir:: ItemId ) {
122118 let id = id. owner_id . def_id ;
123- if let DefKind :: TyAlias = self . tcx . def_kind ( id) {
124- self . type_aliases . push ( id) ;
119+ if let DefKind :: TyAlias = self . collector . tcx . def_kind ( id) {
120+ let items = self . collector . tcx . opaque_types_defined_by ( id) ;
121+ self . collector . opaques . extend ( items) ;
125122 }
126123 }
127124 }
128- let mut visitor = TaitInBodyFinder { type_aliases : Default :: default ( ) , tcx : self . tcx } ;
129- visitor. visit_expr ( body) ;
130- visitor. type_aliases
125+ TaitInBodyFinder { collector : self } . visit_expr ( body) ;
131126 }
132127}
133128
0 commit comments