File tree 2 files changed +13
-8
lines changed
rustc_hir_analysis/src/check
2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -397,14 +397,7 @@ fn check_opaque_meets_bounds<'tcx>(
397
397
) {
398
398
let defining_use_anchor = match * origin {
399
399
hir:: OpaqueTyOrigin :: FnReturn ( did) | hir:: OpaqueTyOrigin :: AsyncFn ( did) => did,
400
- hir:: OpaqueTyOrigin :: TyAlias { .. } => {
401
- let mut def_id = def_id;
402
- // Find the surrounding item (type alias or assoc type)
403
- while let DefKind :: OpaqueTy = tcx. def_kind ( def_id) {
404
- def_id = tcx. local_parent ( def_id) ;
405
- }
406
- def_id
407
- }
400
+ hir:: OpaqueTyOrigin :: TyAlias { .. } => tcx. impl_trait_parent ( def_id) ,
408
401
} ;
409
402
let param_env = tcx. param_env ( defining_use_anchor) ;
410
403
Original file line number Diff line number Diff line change @@ -2476,6 +2476,18 @@ impl<'tcx> TyCtxt<'tcx> {
2476
2476
}
2477
2477
}
2478
2478
2479
+ /// Returns the `DefId` of the item within which the `impl Trait` is declared.
2480
+ /// For type-alias-impl-trait this is the `type` alias.
2481
+ /// For impl-trait-in-assoc-type this is the assoc type.
2482
+ /// For return-position-impl-trait this is the function.
2483
+ pub fn impl_trait_parent ( self , mut def_id : LocalDefId ) -> LocalDefId {
2484
+ // Find the surrounding item (type alias or assoc type)
2485
+ while let DefKind :: OpaqueTy = self . def_kind ( def_id) {
2486
+ def_id = self . local_parent ( def_id) ;
2487
+ }
2488
+ def_id
2489
+ }
2490
+
2479
2491
pub fn impl_method_has_trait_impl_trait_tys ( self , def_id : DefId ) -> bool {
2480
2492
if self . def_kind ( def_id) != DefKind :: AssocFn {
2481
2493
return false ;
You can’t perform that action at this time.
0 commit comments