@@ -47,7 +47,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
4747 let assoc = tcx. associated_item ( assoc_id) ;
4848 match assoc. kind {
4949 ty:: AssocKind :: Const | ty:: AssocKind :: Fn => {
50- locator. check ( assoc_id. expect_local ( ) , true )
50+ locator. check ( assoc_id. expect_local ( ) , ImplTraitSource :: AssocTy )
5151 }
5252 // Associated types don't have bodies, so they can't constrain hidden types
5353 ty:: AssocKind :: Type => { }
@@ -182,9 +182,15 @@ struct TaitConstraintLocator<'tcx> {
182182 typeck_types : Vec < ty:: OpaqueHiddenType < ' tcx > > ,
183183}
184184
185+ #[ derive( Debug ) ]
186+ enum ImplTraitSource {
187+ AssocTy ,
188+ TyAlias ,
189+ }
190+
185191impl TaitConstraintLocator < ' _ > {
186192 #[ instrument( skip( self ) , level = "debug" ) ]
187- fn check ( & mut self , item_def_id : LocalDefId , impl_trait_in_assoc_type : bool ) {
193+ fn check ( & mut self , item_def_id : LocalDefId , source : ImplTraitSource ) {
188194 // Don't try to check items that cannot possibly constrain the type.
189195 if !self . tcx . has_typeck_results ( item_def_id) {
190196 debug ! ( "no constraint: no typeck results" ) ;
@@ -236,10 +242,11 @@ impl TaitConstraintLocator<'_> {
236242 continue ;
237243 }
238244 constrained = true ;
239- let opaque_types_defined_by = if impl_trait_in_assoc_type {
240- self . tcx . impl_trait_in_assoc_types_defined_by ( item_def_id)
241- } else {
242- self . tcx . opaque_types_defined_by ( item_def_id)
245+ let opaque_types_defined_by = match source {
246+ ImplTraitSource :: AssocTy => {
247+ self . tcx . impl_trait_in_assoc_types_defined_by ( item_def_id)
248+ }
249+ ImplTraitSource :: TyAlias => self . tcx . opaque_types_defined_by ( item_def_id) ,
243250 } ;
244251 if !opaque_types_defined_by. contains ( & self . def_id ) {
245252 self . tcx . dcx ( ) . emit_err ( TaitForwardCompat {
@@ -299,29 +306,29 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
299306 }
300307 fn visit_expr ( & mut self , ex : & ' tcx Expr < ' tcx > ) {
301308 if let hir:: ExprKind :: Closure ( closure) = ex. kind {
302- self . check ( closure. def_id , false ) ;
309+ self . check ( closure. def_id , ImplTraitSource :: TyAlias ) ;
303310 }
304311 intravisit:: walk_expr ( self , ex) ;
305312 }
306313 fn visit_item ( & mut self , it : & ' tcx Item < ' tcx > ) {
307314 trace ! ( ?it. owner_id) ;
308315 // The opaque type itself or its children are not within its reveal scope.
309316 if it. owner_id . def_id != self . def_id {
310- self . check ( it. owner_id . def_id , false ) ;
317+ self . check ( it. owner_id . def_id , ImplTraitSource :: TyAlias ) ;
311318 intravisit:: walk_item ( self , it) ;
312319 }
313320 }
314321 fn visit_impl_item ( & mut self , it : & ' tcx ImplItem < ' tcx > ) {
315322 trace ! ( ?it. owner_id) ;
316323 // The opaque type itself or its children are not within its reveal scope.
317324 if it. owner_id . def_id != self . def_id {
318- self . check ( it. owner_id . def_id , false ) ;
325+ self . check ( it. owner_id . def_id , ImplTraitSource :: TyAlias ) ;
319326 intravisit:: walk_impl_item ( self , it) ;
320327 }
321328 }
322329 fn visit_trait_item ( & mut self , it : & ' tcx TraitItem < ' tcx > ) {
323330 trace ! ( ?it. owner_id) ;
324- self . check ( it. owner_id . def_id , false ) ;
331+ self . check ( it. owner_id . def_id , ImplTraitSource :: TyAlias ) ;
325332 intravisit:: walk_trait_item ( self , it) ;
326333 }
327334 fn visit_foreign_item ( & mut self , it : & ' tcx hir:: ForeignItem < ' tcx > ) {
0 commit comments