Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/lib.rs')
-rw-r--r--crates/hir-def/src/lib.rs35
1 files changed, 26 insertions, 9 deletions
diff --git a/crates/hir-def/src/lib.rs b/crates/hir-def/src/lib.rs
index 800c08aa2c..9a7fbc812f 100644
--- a/crates/hir-def/src/lib.rs
+++ b/crates/hir-def/src/lib.rs
@@ -756,19 +756,17 @@ impl GeneralConstId {
}
}
-/// The defs which have a body (have root expressions for type inference).
+/// The defs which have a body.
#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa_macros::Supertype)]
pub enum DefWithBodyId {
+ /// A function body.
FunctionId(FunctionId),
+ /// A static item initializer.
StaticId(StaticId),
+ /// A const item initializer
ConstId(ConstId),
+ /// An enum variant discrimiant
VariantId(EnumVariantId),
- // /// All fields of a variant are inference roots
- // VariantId(VariantId),
- // /// The signature can contain inference roots in a bunch of places
- // /// like const parameters or const arguments in paths
- // This should likely be kept on its own with a separate query
- // GenericDefId(GenericDefId),
}
impl_from!(FunctionId, ConstId, StaticId for DefWithBodyId);
@@ -840,10 +838,15 @@ impl_from!(
/// Owner of an expression store - either a body or a signature.
/// This is used for queries that operate on expression stores generically,
/// such as `expr_scopes`.
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
+// NOTE: This type cannot be `salsa::Supertype` as its variants are overlapping.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord /* !salsa::Supertype */)]
pub enum ExpressionStoreOwnerId {
Signature(GenericDefId),
+ /// A body, something with a root expression.
+ ///
+ /// An enum variant's body is considered its discriminant initializer.
Body(DefWithBodyId),
+ VariantFields(VariantId),
}
impl ExpressionStoreOwnerId {
@@ -861,6 +864,11 @@ impl ExpressionStoreOwnerId {
DefWithBodyId::ConstId(id) => GenericDefId::ConstId(id),
DefWithBodyId::VariantId(it) => it.lookup(db).parent.into(),
},
+ ExpressionStoreOwnerId::VariantFields(variant_id) => match variant_id {
+ VariantId::EnumVariantId(it) => it.lookup(db).parent.into(),
+ VariantId::StructId(it) => it.into(),
+ VariantId::UnionId(it) => it.into(),
+ },
}
}
}
@@ -877,6 +885,12 @@ impl From<DefWithBodyId> for ExpressionStoreOwnerId {
}
}
+impl From<VariantId> for ExpressionStoreOwnerId {
+ fn from(id: VariantId) -> Self {
+ ExpressionStoreOwnerId::VariantFields(id)
+ }
+}
+
impl GenericDefId {
pub fn file_id_and_params_of(
self,
@@ -1017,7 +1031,9 @@ impl From<VariantId> for AttrDefId {
}
}
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa_macros::Supertype, salsa::Update)]
+#[derive(
+ Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, salsa_macros::Supertype, salsa::Update,
+)]
pub enum VariantId {
EnumVariantId(EnumVariantId),
StructId(StructId),
@@ -1241,6 +1257,7 @@ impl HasModule for ExpressionStoreOwnerId {
match self {
ExpressionStoreOwnerId::Signature(def) => def.module(db),
ExpressionStoreOwnerId::Body(def) => def.module(db),
+ ExpressionStoreOwnerId::VariantFields(variant_id) => variant_id.module(db),
}
}
}