@@ -103,31 +103,26 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
103
103
self . tcx . predicates_of ( self . item ) . instantiate_identity ( self . tcx ) . visit_with ( self ) ;
104
104
// An item is allowed to constrain opaques declared within its own body (but not nested within
105
105
// 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 ( ) ;
109
107
}
110
108
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 ) {
113
111
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 > ,
118
114
}
119
- impl < ' v > intravisit:: Visitor < ' v > for TaitInBodyFinder < ' _ > {
115
+ impl < ' v > intravisit:: Visitor < ' v > for TaitInBodyFinder < ' _ , ' _ > {
120
116
#[ instrument( level = "trace" , skip( self ) ) ]
121
117
fn visit_nested_item ( & mut self , id : rustc_hir:: ItemId ) {
122
118
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) ;
125
122
}
126
123
}
127
124
}
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) ;
131
126
}
132
127
}
133
128
0 commit comments