@@ -112,13 +112,17 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
112112 }
113113 TaitInBodyFinder { collector : self } . visit_expr ( body) ;
114114 }
115+ }
115116
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 > ;
116121 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 ( ) ) {
118123 return ;
119124 }
120-
121- let tcx = self . tcx ;
125+ let tcx = self . collector ( ) . tcx ;
122126
123127 // TAITs outside their defining scopes are ignored.
124128 let origin = tcx. opaque_type_origin ( alias_ty. def_id . expect_local ( ) ) ;
@@ -127,14 +131,14 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
127131 rustc_hir:: OpaqueTyOrigin :: FnReturn ( _) | rustc_hir:: OpaqueTyOrigin :: AsyncFn ( _) => { }
128132 rustc_hir:: OpaqueTyOrigin :: TyAlias { in_assoc_ty } => {
129133 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 ( ) ) {
131135 return ;
132136 }
133137 }
134138 }
135139 }
136140
137- self . opaques . push ( alias_ty. def_id . expect_local ( ) ) ;
141+ self . collector ( ) . opaques . push ( alias_ty. def_id . expect_local ( ) ) ;
138142
139143 let parent_count = tcx. generics_of ( alias_ty. def_id ) . parent_count ;
140144 // Only check that the parent generics of the TAIT/RPIT are unique.
@@ -161,21 +165,27 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
161165 Err ( NotUniqueParam :: NotParam ( arg) ) => {
162166 tcx. dcx ( ) . emit_err ( NotParam {
163167 arg,
164- span : self . span ( ) ,
168+ span : self . collector ( ) . span ( ) ,
165169 opaque_span : tcx. def_span ( alias_ty. def_id ) ,
166170 } ) ;
167171 }
168172 Err ( NotUniqueParam :: DuplicateParam ( arg) ) => {
169173 tcx. dcx ( ) . emit_err ( DuplicateArg {
170174 arg,
171- span : self . span ( ) ,
175+ span : self . collector ( ) . span ( ) ,
172176 opaque_span : tcx. def_span ( alias_ty. def_id ) ,
173177 } ) ;
174178 }
175179 }
176180 }
177181}
178182
183+ impl < ' tcx > OpaqueFinderVisitor < ' tcx > for OpaqueTypeCollector < ' tcx > {
184+ fn collector ( & mut self ) -> & mut OpaqueTypeCollector < ' tcx > {
185+ self
186+ }
187+ }
188+
179189impl < ' tcx > SpannedTypeVisitor < ' tcx > for OpaqueTypeCollector < ' tcx > {
180190 #[ instrument( skip( self ) , ret, level = "trace" ) ]
181191 fn visit ( & mut self , span : Span , value : impl TypeVisitable < TyCtxt < ' tcx > > ) -> ControlFlow < !> {
@@ -273,6 +283,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
273283
274284struct ImplTraitInAssocTypeCollector < ' tcx > ( OpaqueTypeCollector < ' tcx > ) ;
275285
286+ impl < ' tcx > OpaqueFinderVisitor < ' tcx > for ImplTraitInAssocTypeCollector < ' tcx > {
287+ fn collector ( & mut self ) -> & mut OpaqueTypeCollector < ' tcx > {
288+ & mut self . 0
289+ }
290+ }
291+
276292impl < ' tcx > SpannedTypeVisitor < ' tcx > for ImplTraitInAssocTypeCollector < ' tcx > {
277293 #[ instrument( skip( self ) , ret, level = "trace" ) ]
278294 fn visit ( & mut self , span : Span , value : impl TypeVisitable < TyCtxt < ' tcx > > ) -> ControlFlow < !> {
@@ -291,7 +307,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInAssocTypeCollector<'tcx> {
291307 t. super_visit_with ( self ) ?;
292308 match t. kind ( ) {
293309 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) ;
295311 }
296312 ty:: Alias ( ty:: Projection , alias_ty) => {
297313 // This avoids having to do normalization of `Self::AssocTy` by only
0 commit comments