From 6f3d0f779684e3755f6d5b6ea2ce6865f8d484cb Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 1 Sep 2025 15:05:57 -0500 Subject: [PATCH] Introduce qpath lang item utils --- compiler/rustc_middle/src/hir/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 9e3162785f4b..42150dd6a190 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -10,7 +10,7 @@ use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in}; -use rustc_hir::def::DefKind; +use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId}; use rustc_hir::lints::DelayedLint; use rustc_hir::*; @@ -203,6 +203,20 @@ pub fn hash_owner_nodes( } }) } + + pub fn qpath_is_lang_item(self, qpath: QPath<'_>, lang_item: LangItem) -> bool { + self.qpath_lang_item(qpath) == Some(lang_item) + } + + /// This does not use typeck results since this is intended to be used with generated code. + pub fn qpath_lang_item(self, qpath: QPath<'_>) -> Option { + if let QPath::Resolved(_, path) = qpath + && let Res::Def(_, def_id) = path.res + { + return self.lang_items().from_def_id(def_id); + } + None + } } /// Hashes computed by [`TyCtxt::hash_owner_nodes`] if necessary.