@@ -47,7 +47,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
47
47
let assoc = tcx. associated_item ( assoc_id) ;
48
48
match assoc. kind {
49
49
ty:: AssocKind :: Const | ty:: AssocKind :: Fn => {
50
- locator. check ( assoc_id. expect_local ( ) , true )
50
+ locator. check ( assoc_id. expect_local ( ) , ImplTraitSource :: AssocTy )
51
51
}
52
52
// Associated types don't have bodies, so they can't constrain hidden types
53
53
ty:: AssocKind :: Type => { }
@@ -182,9 +182,15 @@ struct TaitConstraintLocator<'tcx> {
182
182
typeck_types : Vec < ty:: OpaqueHiddenType < ' tcx > > ,
183
183
}
184
184
185
+ #[ derive( Debug ) ]
186
+ enum ImplTraitSource {
187
+ AssocTy ,
188
+ TyAlias ,
189
+ }
190
+
185
191
impl TaitConstraintLocator < ' _ > {
186
192
#[ 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 ) {
188
194
// Don't try to check items that cannot possibly constrain the type.
189
195
if !self . tcx . has_typeck_results ( item_def_id) {
190
196
debug ! ( "no constraint: no typeck results" ) ;
@@ -236,10 +242,11 @@ impl TaitConstraintLocator<'_> {
236
242
continue ;
237
243
}
238
244
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) ,
243
250
} ;
244
251
if !opaque_types_defined_by. contains ( & self . def_id ) {
245
252
self . tcx . dcx ( ) . emit_err ( TaitForwardCompat {
@@ -299,29 +306,29 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
299
306
}
300
307
fn visit_expr ( & mut self , ex : & ' tcx Expr < ' tcx > ) {
301
308
if let hir:: ExprKind :: Closure ( closure) = ex. kind {
302
- self . check ( closure. def_id , false ) ;
309
+ self . check ( closure. def_id , ImplTraitSource :: TyAlias ) ;
303
310
}
304
311
intravisit:: walk_expr ( self , ex) ;
305
312
}
306
313
fn visit_item ( & mut self , it : & ' tcx Item < ' tcx > ) {
307
314
trace ! ( ?it. owner_id) ;
308
315
// The opaque type itself or its children are not within its reveal scope.
309
316
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 ) ;
311
318
intravisit:: walk_item ( self , it) ;
312
319
}
313
320
}
314
321
fn visit_impl_item ( & mut self , it : & ' tcx ImplItem < ' tcx > ) {
315
322
trace ! ( ?it. owner_id) ;
316
323
// The opaque type itself or its children are not within its reveal scope.
317
324
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 ) ;
319
326
intravisit:: walk_impl_item ( self , it) ;
320
327
}
321
328
}
322
329
fn visit_trait_item ( & mut self , it : & ' tcx TraitItem < ' tcx > ) {
323
330
trace ! ( ?it. owner_id) ;
324
- self . check ( it. owner_id . def_id , false ) ;
331
+ self . check ( it. owner_id . def_id , ImplTraitSource :: TyAlias ) ;
325
332
intravisit:: walk_trait_item ( self , it) ;
326
333
}
327
334
fn visit_foreign_item ( & mut self , it : & ' tcx hir:: ForeignItem < ' tcx > ) {
0 commit comments