diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-04-25 11:43:08 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-05-12 10:25:34 +0000 |
| commit | e2daccc4acbb7a3150e1aef32f8cbe2736e5bd99 (patch) | |
| tree | 72bc74c7e186f6b2a05fc6becaf0003647cd8fba | |
| parent | 84a43f0e3aa9b76bc9cef952d25b41ed1e5e0a94 (diff) | |
| download | rust-e2daccc4acbb7a3150e1aef32f8cbe2736e5bd99.tar.gz rust-e2daccc4acbb7a3150e1aef32f8cbe2736e5bd99.zip | |
Add a convenience function
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/check.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 12 |
2 files changed, 13 insertions, 8 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index b16860907eb..78ffe59679a 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -397,14 +397,7 @@ fn check_opaque_meets_bounds<'tcx>( ) { let defining_use_anchor = match *origin { hir::OpaqueTyOrigin::FnReturn(did) | hir::OpaqueTyOrigin::AsyncFn(did) => did, - hir::OpaqueTyOrigin::TyAlias { .. } => { - let mut def_id = def_id; - // Find the surrounding item (type alias or assoc type) - while let DefKind::OpaqueTy = tcx.def_kind(def_id) { - def_id = tcx.local_parent(def_id); - } - def_id - } + hir::OpaqueTyOrigin::TyAlias { .. } => tcx.impl_trait_parent(def_id), }; let param_env = tcx.param_env(defining_use_anchor); diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 2952217f267..b414e1200cd 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2476,6 +2476,18 @@ impl<'tcx> TyCtxt<'tcx> { } } + /// Returns the `DefId` of the item within which the `impl Trait` is declared. + /// For type-alias-impl-trait this is the `type` alias. + /// For impl-trait-in-assoc-type this is the assoc type. + /// For return-position-impl-trait this is the function. + pub fn impl_trait_parent(self, mut def_id: LocalDefId) -> LocalDefId { + // Find the surrounding item (type alias or assoc type) + while let DefKind::OpaqueTy = self.def_kind(def_id) { + def_id = self.local_parent(def_id); + } + def_id + } + pub fn impl_method_has_trait_impl_trait_tys(self, def_id: DefId) -> bool { if self.def_kind(def_id) != DefKind::AssocFn { return false; |
