@@ -45,7 +45,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
4545 let assoc = tcx. associated_item ( assoc_id) ;
4646 match assoc. kind {
4747 ty:: AssocKind :: Const | ty:: AssocKind :: Fn => {
48- locator. check ( assoc_id. expect_local ( ) , true )
48+ locator. check ( assoc_id. expect_local ( ) , ImplTraitSource :: AssocTy )
4949 }
5050 // Associated types don't have bodies, so they can't constrain hidden types
5151 ty:: AssocKind :: Type => { }
@@ -180,9 +180,15 @@ struct TaitConstraintLocator<'tcx> {
180180 typeck_types : Vec < ty:: OpaqueHiddenType < ' tcx > > ,
181181}
182182
183+ #[ derive( Debug ) ]
184+ enum ImplTraitSource {
185+ AssocTy ,
186+ TyAlias ,
187+ }
188+
183189impl TaitConstraintLocator < ' _ > {
184190 #[ instrument( skip( self ) , level = "debug" ) ]
185- fn check ( & mut self , item_def_id : LocalDefId , impl_trait_in_assoc_type : bool ) {
191+ fn check ( & mut self , item_def_id : LocalDefId , source : ImplTraitSource ) {
186192 // Don't try to check items that cannot possibly constrain the type.
187193 if !self . tcx . has_typeck_results ( item_def_id) {
188194 debug ! ( "no constraint: no typeck results" ) ;
@@ -212,10 +218,11 @@ impl TaitConstraintLocator<'_> {
212218 continue ;
213219 }
214220 constrained = true ;
215- let opaque_types_defined_by = if impl_trait_in_assoc_type {
216- self . tcx . impl_trait_in_assoc_types_defined_by ( item_def_id)
217- } else {
218- self . tcx . opaque_types_defined_by ( item_def_id)
221+ let opaque_types_defined_by = match source {
222+ ImplTraitSource :: AssocTy => {
223+ self . tcx . impl_trait_in_assoc_types_defined_by ( item_def_id)
224+ }
225+ ImplTraitSource :: TyAlias => self . tcx . opaque_types_defined_by ( item_def_id) ,
219226 } ;
220227 if !opaque_types_defined_by. contains ( & self . def_id ) {
221228 self . tcx . dcx ( ) . emit_err ( TaitForwardCompat {
@@ -275,29 +282,29 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
275282 }
276283 fn visit_expr ( & mut self , ex : & ' tcx Expr < ' tcx > ) {
277284 if let hir:: ExprKind :: Closure ( closure) = ex. kind {
278- self . check ( closure. def_id , false ) ;
285+ self . check ( closure. def_id , ImplTraitSource :: TyAlias ) ;
279286 }
280287 intravisit:: walk_expr ( self , ex) ;
281288 }
282289 fn visit_item ( & mut self , it : & ' tcx Item < ' tcx > ) {
283290 trace ! ( ?it. owner_id) ;
284291 // The opaque type itself or its children are not within its reveal scope.
285292 if it. owner_id . def_id != self . def_id {
286- self . check ( it. owner_id . def_id , false ) ;
293+ self . check ( it. owner_id . def_id , ImplTraitSource :: TyAlias ) ;
287294 intravisit:: walk_item ( self , it) ;
288295 }
289296 }
290297 fn visit_impl_item ( & mut self , it : & ' tcx ImplItem < ' tcx > ) {
291298 trace ! ( ?it. owner_id) ;
292299 // The opaque type itself or its children are not within its reveal scope.
293300 if it. owner_id . def_id != self . def_id {
294- self . check ( it. owner_id . def_id , false ) ;
301+ self . check ( it. owner_id . def_id , ImplTraitSource :: TyAlias ) ;
295302 intravisit:: walk_impl_item ( self , it) ;
296303 }
297304 }
298305 fn visit_trait_item ( & mut self , it : & ' tcx TraitItem < ' tcx > ) {
299306 trace ! ( ?it. owner_id) ;
300- self . check ( it. owner_id . def_id , false ) ;
307+ self . check ( it. owner_id . def_id , ImplTraitSource :: TyAlias ) ;
301308 intravisit:: walk_trait_item ( self , it) ;
302309 }
303310 fn visit_foreign_item ( & mut self , it : & ' tcx hir:: ForeignItem < ' tcx > ) {
0 commit comments