@@ -112,13 +112,17 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
112
112
}
113
113
TaitInBodyFinder { collector : self } . visit_expr ( body) ;
114
114
}
115
+ }
115
116
117
+ /// A helper trait that ensures that we can recurse with the right TypeVisitor
118
+ /// when looking at projections on the opaque type's bounds.
119
+ trait OpaqueFinderVisitor < ' tcx > : SpannedTypeVisitor < ' tcx > {
120
+ fn collector ( & mut self ) -> & mut OpaqueTypeCollector < ' tcx > ;
116
121
fn visit_opaque_ty ( & mut self , alias_ty : & ty:: AliasTy < ' tcx > ) {
117
- if !self . seen . insert ( alias_ty. def_id . expect_local ( ) ) {
122
+ if !self . collector ( ) . seen . insert ( alias_ty. def_id . expect_local ( ) ) {
118
123
return ;
119
124
}
120
-
121
- let tcx = self . tcx ;
125
+ let tcx = self . collector ( ) . tcx ;
122
126
123
127
// TAITs outside their defining scopes are ignored.
124
128
let origin = tcx. opaque_type_origin ( alias_ty. def_id . expect_local ( ) ) ;
@@ -127,14 +131,14 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
127
131
rustc_hir:: OpaqueTyOrigin :: FnReturn ( _) | rustc_hir:: OpaqueTyOrigin :: AsyncFn ( _) => { }
128
132
rustc_hir:: OpaqueTyOrigin :: TyAlias { in_assoc_ty } => {
129
133
if !in_assoc_ty {
130
- if !self . check_tait_defining_scope ( alias_ty. def_id . expect_local ( ) ) {
134
+ if !self . collector ( ) . check_tait_defining_scope ( alias_ty. def_id . expect_local ( ) ) {
131
135
return ;
132
136
}
133
137
}
134
138
}
135
139
}
136
140
137
- self . opaques . push ( alias_ty. def_id . expect_local ( ) ) ;
141
+ self . collector ( ) . opaques . push ( alias_ty. def_id . expect_local ( ) ) ;
138
142
139
143
let parent_count = tcx. generics_of ( alias_ty. def_id ) . parent_count ;
140
144
// Only check that the parent generics of the TAIT/RPIT are unique.
@@ -161,21 +165,27 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
161
165
Err ( NotUniqueParam :: NotParam ( arg) ) => {
162
166
tcx. dcx ( ) . emit_err ( NotParam {
163
167
arg,
164
- span : self . span ( ) ,
168
+ span : self . collector ( ) . span ( ) ,
165
169
opaque_span : tcx. def_span ( alias_ty. def_id ) ,
166
170
} ) ;
167
171
}
168
172
Err ( NotUniqueParam :: DuplicateParam ( arg) ) => {
169
173
tcx. dcx ( ) . emit_err ( DuplicateArg {
170
174
arg,
171
- span : self . span ( ) ,
175
+ span : self . collector ( ) . span ( ) ,
172
176
opaque_span : tcx. def_span ( alias_ty. def_id ) ,
173
177
} ) ;
174
178
}
175
179
}
176
180
}
177
181
}
178
182
183
+ impl < ' tcx > OpaqueFinderVisitor < ' tcx > for OpaqueTypeCollector < ' tcx > {
184
+ fn collector ( & mut self ) -> & mut OpaqueTypeCollector < ' tcx > {
185
+ self
186
+ }
187
+ }
188
+
179
189
impl < ' tcx > SpannedTypeVisitor < ' tcx > for OpaqueTypeCollector < ' tcx > {
180
190
#[ instrument( skip( self ) , ret, level = "trace" ) ]
181
191
fn visit ( & mut self , span : Span , value : impl TypeVisitable < TyCtxt < ' tcx > > ) -> ControlFlow < !> {
@@ -273,6 +283,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
273
283
274
284
struct ImplTraitInAssocTypeCollector < ' tcx > ( OpaqueTypeCollector < ' tcx > ) ;
275
285
286
+ impl < ' tcx > OpaqueFinderVisitor < ' tcx > for ImplTraitInAssocTypeCollector < ' tcx > {
287
+ fn collector ( & mut self ) -> & mut OpaqueTypeCollector < ' tcx > {
288
+ & mut self . 0
289
+ }
290
+ }
291
+
276
292
impl < ' tcx > SpannedTypeVisitor < ' tcx > for ImplTraitInAssocTypeCollector < ' tcx > {
277
293
#[ instrument( skip( self ) , ret, level = "trace" ) ]
278
294
fn visit ( & mut self , span : Span , value : impl TypeVisitable < TyCtxt < ' tcx > > ) -> ControlFlow < !> {
@@ -291,7 +307,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInAssocTypeCollector<'tcx> {
291
307
t. super_visit_with ( self ) ?;
292
308
match t. kind ( ) {
293
309
ty:: Alias ( ty:: Opaque , alias_ty) if alias_ty. def_id . is_local ( ) => {
294
- self . 0 . visit_opaque_ty ( alias_ty) ;
310
+ self . visit_opaque_ty ( alias_ty) ;
295
311
}
296
312
ty:: Alias ( ty:: Projection , alias_ty) => {
297
313
// This avoids having to do normalization of `Self::AssocTy` by only
0 commit comments