diff options
| author | Cameron Steffen <cam.steffen94@gmail.com> | 2025-08-15 16:12:35 -0500 |
|---|---|---|
| committer | Cameron Steffen <cam.steffen94@gmail.com> | 2025-09-12 15:10:30 -0500 |
| commit | 16c218c57ff83c82ba58753c3a67f697e260adc1 (patch) | |
| tree | e494843e44d3eacda9db664c0d3b5581639e220c /compiler/rustc_middle | |
| parent | a171994070dc18c3a32fc1aa2d98cf03ae96b63e (diff) | |
| download | rust-16c218c57ff83c82ba58753c3a67f697e260adc1.tar.gz rust-16c218c57ff83c82ba58753c3a67f697e260adc1.zip | |
Introduce trait_item_of
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index da17ec1f9f3..5a4ebfe28a4 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1934,6 +1934,15 @@ impl<'tcx> TyCtxt<'tcx> { Some((parent, def_kind)) } + /// Returns the trait item that is implemented by the given item `DefId`. + pub fn trait_item_of(self, def_id: impl IntoQueryParam<DefId>) -> Option<DefId> { + let assoc = self.opt_associated_item(def_id.into_query_param())?; + if assoc.container != AssocItemContainer::Impl { + return None; + } + assoc.trait_item_def_id + } + /// If the given `DefId` is an associated item of a trait, /// returns the `DefId` of the trait; otherwise, returns `None`. pub fn trait_of_assoc(self, def_id: DefId) -> Option<DefId> { |
