mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-03 17:35:28 +03:00
Introduce qpath lang item utils
This commit is contained in:
@@ -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<LangItem> {
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user