Skip to content

Commit 6f3d0f7

Browse files
committed
Introduce qpath lang item utils
1 parent 34a8c73 commit 6f3d0f7

File tree

1 file changed

+15
-1
lines changed
  • compiler/rustc_middle/src/hir

1 file changed

+15
-1
lines changed

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
1010
use rustc_data_structures::sorted_map::SortedMap;
1111
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in};
13-
use rustc_hir::def::DefKind;
13+
use rustc_hir::def::{DefKind, Res};
1414
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
1515
use rustc_hir::lints::DelayedLint;
1616
use rustc_hir::*;
@@ -203,6 +203,20 @@ impl<'tcx> TyCtxt<'tcx> {
203203
}
204204
})
205205
}
206+
207+
pub fn qpath_is_lang_item(self, qpath: QPath<'_>, lang_item: LangItem) -> bool {
208+
self.qpath_lang_item(qpath) == Some(lang_item)
209+
}
210+
211+
/// This does not use typeck results since this is intended to be used with generated code.
212+
pub fn qpath_lang_item(self, qpath: QPath<'_>) -> Option<LangItem> {
213+
if let QPath::Resolved(_, path) = qpath
214+
&& let Res::Def(_, def_id) = path.res
215+
{
216+
return self.lang_items().from_def_id(def_id);
217+
}
218+
None
219+
}
206220
}
207221

208222
/// Hashes computed by [`TyCtxt::hash_owner_nodes`] if necessary.

0 commit comments

Comments
 (0)