Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/lang_item.rs')
-rw-r--r--crates/hir-def/src/lang_item.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/crates/hir-def/src/lang_item.rs b/crates/hir-def/src/lang_item.rs
index 600f206770..df0705bf90 100644
--- a/crates/hir-def/src/lang_item.rs
+++ b/crates/hir-def/src/lang_item.rs
@@ -84,6 +84,15 @@ impl LangItemTarget {
_ => None,
}
}
+
+ pub fn as_adt(self) -> Option<AdtId> {
+ match self {
+ LangItemTarget::Union(it) => Some(it.into()),
+ LangItemTarget::EnumId(it) => Some(it.into()),
+ LangItemTarget::Struct(it) => Some(it.into()),
+ _ => None,
+ }
+ }
}
/// Salsa query. This will look for lang items in a specific crate.
@@ -289,6 +298,10 @@ impl LangItem {
lang_item(db, start_crate, self).and_then(|t| t.as_trait())
}
+ pub fn resolve_adt(self, db: &dyn DefDatabase, start_crate: Crate) -> Option<AdtId> {
+ lang_item(db, start_crate, self).and_then(|t| t.as_adt())
+ }
+
pub fn resolve_enum(self, db: &dyn DefDatabase, start_crate: Crate) -> Option<EnumId> {
lang_item(db, start_crate, self).and_then(|t| t.as_enum())
}