mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Implement type inference for enum variants
This commit is contained in:
parent
aca14c591f
commit
978de5cf8b
12 changed files with 218 additions and 45 deletions
|
@ -44,6 +44,7 @@ pub enum Def {
|
|||
Module(Module),
|
||||
Struct(Struct),
|
||||
Enum(Enum),
|
||||
EnumVariant(EnumVariant),
|
||||
Function(Function),
|
||||
Item,
|
||||
}
|
||||
|
@ -188,6 +189,10 @@ pub struct Enum {
|
|||
}
|
||||
|
||||
impl Enum {
|
||||
pub(crate) fn new(def_id: DefId) -> Self {
|
||||
Enum { def_id }
|
||||
}
|
||||
|
||||
pub fn def_id(&self) -> DefId {
|
||||
self.def_id
|
||||
}
|
||||
|
@ -196,11 +201,38 @@ impl Enum {
|
|||
Ok(db.enum_data(self.def_id)?.name.clone())
|
||||
}
|
||||
|
||||
pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Vec<(Name, Arc<VariantData>)>> {
|
||||
pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Option<Vec<EnumVariant>>> {
|
||||
Ok(db.enum_data(self.def_id)?.variants.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct EnumVariant {
|
||||
pub(crate) def_id: DefId,
|
||||
}
|
||||
|
||||
impl EnumVariant {
|
||||
pub(crate) fn new(def_id: DefId) -> Self {
|
||||
EnumVariant { def_id }
|
||||
}
|
||||
|
||||
pub fn def_id(&self) -> DefId {
|
||||
self.def_id
|
||||
}
|
||||
|
||||
pub fn parent_enum(&self, db: &impl HirDatabase) -> Cancelable<Enum> {
|
||||
Ok(db.enum_variant_data(self.def_id)?.parent_enum.clone())
|
||||
}
|
||||
|
||||
pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
|
||||
Ok(db.enum_variant_data(self.def_id)?.name.clone())
|
||||
}
|
||||
|
||||
pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> {
|
||||
Ok(db.enum_variant_data(self.def_id)?.variant_data.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Function {
|
||||
pub(crate) def_id: DefId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue