@@ -45,7 +45,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
45
45
let assoc = tcx. associated_item ( assoc_id) ;
46
46
match assoc. kind {
47
47
ty:: AssocKind :: Const | ty:: AssocKind :: Fn => {
48
- locator. check ( assoc_id. expect_local ( ) , true )
48
+ locator. check ( assoc_id. expect_local ( ) , ImplTraitSource :: AssocTy )
49
49
}
50
50
// Associated types don't have bodies, so they can't constrain hidden types
51
51
ty:: AssocKind :: Type => { }
@@ -180,9 +180,15 @@ struct TaitConstraintLocator<'tcx> {
180
180
typeck_types : Vec < ty:: OpaqueHiddenType < ' tcx > > ,
181
181
}
182
182
183
+ #[ derive( Debug ) ]
184
+ enum ImplTraitSource {
185
+ AssocTy ,
186
+ TyAlias ,
187
+ }
188
+
183
189
impl TaitConstraintLocator < ' _ > {
184
190
#[ 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 ) {
186
192
// Don't try to check items that cannot possibly constrain the type.
187
193
if !self . tcx . has_typeck_results ( item_def_id) {
188
194
debug ! ( "no constraint: no typeck results" ) ;
@@ -212,10 +218,11 @@ impl TaitConstraintLocator<'_> {
212
218
continue ;
213
219
}
214
220
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) ,
219
226
} ;
220
227
if !opaque_types_defined_by. contains ( & self . def_id ) {
221
228
self . tcx . dcx ( ) . emit_err ( TaitForwardCompat {
@@ -275,29 +282,29 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
275
282
}
276
283
fn visit_expr ( & mut self , ex : & ' tcx Expr < ' tcx > ) {
277
284
if let hir:: ExprKind :: Closure ( closure) = ex. kind {
278
- self . check ( closure. def_id , false ) ;
285
+ self . check ( closure. def_id , ImplTraitSource :: TyAlias ) ;
279
286
}
280
287
intravisit:: walk_expr ( self , ex) ;
281
288
}
282
289
fn visit_item ( & mut self , it : & ' tcx Item < ' tcx > ) {
283
290
trace ! ( ?it. owner_id) ;
284
291
// The opaque type itself or its children are not within its reveal scope.
285
292
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 ) ;
287
294
intravisit:: walk_item ( self , it) ;
288
295
}
289
296
}
290
297
fn visit_impl_item ( & mut self , it : & ' tcx ImplItem < ' tcx > ) {
291
298
trace ! ( ?it. owner_id) ;
292
299
// The opaque type itself or its children are not within its reveal scope.
293
300
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 ) ;
295
302
intravisit:: walk_impl_item ( self , it) ;
296
303
}
297
304
}
298
305
fn visit_trait_item ( & mut self , it : & ' tcx TraitItem < ' tcx > ) {
299
306
trace ! ( ?it. owner_id) ;
300
- self . check ( it. owner_id . def_id , false ) ;
307
+ self . check ( it. owner_id . def_id , ImplTraitSource :: TyAlias ) ;
301
308
intravisit:: walk_trait_item ( self , it) ;
302
309
}
303
310
fn visit_foreign_item ( & mut self , it : & ' tcx hir:: ForeignItem < ' tcx > ) {
0 commit comments