mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Enum variants are not generic def ids
This commit is contained in:
parent
3432ef4414
commit
3168ab5b99
22 changed files with 188 additions and 178 deletions
|
@ -689,7 +689,7 @@ pub enum TypeOwnerId {
|
|||
}
|
||||
|
||||
impl TypeOwnerId {
|
||||
fn as_generic_def_id(self) -> Option<GenericDefId> {
|
||||
fn as_generic_def_id(self, db: &dyn DefDatabase) -> Option<GenericDefId> {
|
||||
Some(match self {
|
||||
TypeOwnerId::FunctionId(it) => GenericDefId::FunctionId(it),
|
||||
TypeOwnerId::ConstId(it) => GenericDefId::ConstId(it),
|
||||
|
@ -698,7 +698,9 @@ impl TypeOwnerId {
|
|||
TypeOwnerId::TraitAliasId(it) => GenericDefId::TraitAliasId(it),
|
||||
TypeOwnerId::TypeAliasId(it) => GenericDefId::TypeAliasId(it),
|
||||
TypeOwnerId::ImplId(it) => GenericDefId::ImplId(it),
|
||||
TypeOwnerId::EnumVariantId(it) => GenericDefId::EnumVariantId(it),
|
||||
TypeOwnerId::EnumVariantId(it) => {
|
||||
GenericDefId::AdtId(AdtId::EnumId(it.lookup(db).parent))
|
||||
}
|
||||
TypeOwnerId::InTypeConstId(_) | TypeOwnerId::StaticId(_) => return None,
|
||||
})
|
||||
}
|
||||
|
@ -740,7 +742,6 @@ impl From<GenericDefId> for TypeOwnerId {
|
|||
GenericDefId::TraitAliasId(it) => it.into(),
|
||||
GenericDefId::TypeAliasId(it) => it.into(),
|
||||
GenericDefId::ImplId(it) => it.into(),
|
||||
GenericDefId::EnumVariantId(it) => it.into(),
|
||||
GenericDefId::ConstId(it) => it.into(),
|
||||
}
|
||||
}
|
||||
|
@ -849,8 +850,8 @@ impl GeneralConstId {
|
|||
pub fn generic_def(self, db: &dyn DefDatabase) -> Option<GenericDefId> {
|
||||
match self {
|
||||
GeneralConstId::ConstId(it) => Some(it.into()),
|
||||
GeneralConstId::ConstBlockId(it) => it.lookup(db).parent.as_generic_def_id(),
|
||||
GeneralConstId::InTypeConstId(it) => it.lookup(db).owner.as_generic_def_id(),
|
||||
GeneralConstId::ConstBlockId(it) => it.lookup(db).parent.as_generic_def_id(db),
|
||||
GeneralConstId::InTypeConstId(it) => it.lookup(db).owner.as_generic_def_id(db),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -888,12 +889,12 @@ impl From<EnumVariantId> for DefWithBodyId {
|
|||
}
|
||||
|
||||
impl DefWithBodyId {
|
||||
pub fn as_generic_def_id(self) -> Option<GenericDefId> {
|
||||
pub fn as_generic_def_id(self, db: &dyn DefDatabase) -> Option<GenericDefId> {
|
||||
match self {
|
||||
DefWithBodyId::FunctionId(f) => Some(f.into()),
|
||||
DefWithBodyId::StaticId(_) => None,
|
||||
DefWithBodyId::ConstId(c) => Some(c.into()),
|
||||
DefWithBodyId::VariantId(c) => Some(c.into()),
|
||||
DefWithBodyId::VariantId(c) => Some(c.lookup(db).parent.into()),
|
||||
// FIXME: stable rust doesn't allow generics in constants, but we should
|
||||
// use `TypeOwnerId::as_generic_def_id` when it does.
|
||||
DefWithBodyId::InTypeConstId(_) => None,
|
||||
|
@ -921,10 +922,6 @@ pub enum GenericDefId {
|
|||
TraitAliasId(TraitAliasId),
|
||||
TypeAliasId(TypeAliasId),
|
||||
ImplId(ImplId),
|
||||
// enum variants cannot have generics themselves, but their parent enums
|
||||
// can, and this makes some code easier to write
|
||||
// FIXME: Try to remove this as that will reduce the amount of query slots generated per enum?
|
||||
EnumVariantId(EnumVariantId),
|
||||
// consts can have type parameters from their parents (i.e. associated consts of traits)
|
||||
ConstId(ConstId),
|
||||
}
|
||||
|
@ -935,7 +932,6 @@ impl_from!(
|
|||
TraitAliasId,
|
||||
TypeAliasId,
|
||||
ImplId,
|
||||
EnumVariantId,
|
||||
ConstId
|
||||
for GenericDefId
|
||||
);
|
||||
|
@ -967,7 +963,6 @@ impl GenericDefId {
|
|||
GenericDefId::TraitAliasId(it) => file_id_and_params_of_item_loc(db, it),
|
||||
GenericDefId::ImplId(it) => file_id_and_params_of_item_loc(db, it),
|
||||
GenericDefId::ConstId(it) => (it.lookup(db).id.file_id(), None),
|
||||
GenericDefId::EnumVariantId(it) => (it.lookup(db).id.file_id(), None),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -994,6 +989,46 @@ impl From<AssocItemId> for GenericDefId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum CallableDefId {
|
||||
FunctionId(FunctionId),
|
||||
StructId(StructId),
|
||||
EnumVariantId(EnumVariantId),
|
||||
}
|
||||
|
||||
impl InternValueTrivial for CallableDefId {}
|
||||
|
||||
impl_from!(FunctionId, StructId, EnumVariantId for CallableDefId);
|
||||
impl From<CallableDefId> for ModuleDefId {
|
||||
fn from(def: CallableDefId) -> ModuleDefId {
|
||||
match def {
|
||||
CallableDefId::FunctionId(f) => ModuleDefId::FunctionId(f),
|
||||
CallableDefId::StructId(s) => ModuleDefId::AdtId(AdtId::StructId(s)),
|
||||
CallableDefId::EnumVariantId(e) => ModuleDefId::EnumVariantId(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CallableDefId {
|
||||
pub fn krate(self, db: &dyn DefDatabase) -> CrateId {
|
||||
match self {
|
||||
CallableDefId::FunctionId(f) => f.krate(db),
|
||||
CallableDefId::StructId(s) => s.krate(db),
|
||||
CallableDefId::EnumVariantId(e) => e.krate(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GenericDefId {
|
||||
pub fn from(db: &dyn DefDatabase, def: CallableDefId) -> GenericDefId {
|
||||
match def {
|
||||
CallableDefId::FunctionId(f) => f.into(),
|
||||
CallableDefId::StructId(s) => s.into(),
|
||||
CallableDefId::EnumVariantId(e) => e.lookup(db).parent.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum AttrDefId {
|
||||
ModuleId(ModuleId),
|
||||
|
@ -1310,7 +1345,6 @@ impl HasModule for GenericDefId {
|
|||
GenericDefId::TraitAliasId(it) => it.module(db),
|
||||
GenericDefId::TypeAliasId(it) => it.module(db),
|
||||
GenericDefId::ImplId(it) => it.module(db),
|
||||
GenericDefId::EnumVariantId(it) => it.module(db),
|
||||
GenericDefId::ConstId(it) => it.module(db),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue