mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Remove hir/adt.rs
This commit is contained in:
parent
12ec946216
commit
7c275a7ed2
6 changed files with 47 additions and 66 deletions
|
@ -23,7 +23,6 @@ use ra_db::{CrateId, Edition};
|
|||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||
|
||||
use crate::{
|
||||
adt::VariantDef,
|
||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
||||
expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId},
|
||||
generics::{GenericDef, HasGenericParams},
|
||||
|
@ -324,6 +323,10 @@ impl Struct {
|
|||
// ...and add generic params, if present
|
||||
r.push_generic_params_scope(db, self.into())
|
||||
}
|
||||
|
||||
fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
|
||||
db.struct_data(self.id.into()).variant_data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
|
@ -482,6 +485,43 @@ impl Adt {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum VariantDef {
|
||||
Struct(Struct),
|
||||
EnumVariant(EnumVariant),
|
||||
}
|
||||
impl_froms!(VariantDef: Struct, EnumVariant);
|
||||
|
||||
impl VariantDef {
|
||||
pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> {
|
||||
match self {
|
||||
VariantDef::Struct(it) => it.fields(db),
|
||||
VariantDef::EnumVariant(it) => it.fields(db),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> {
|
||||
match self {
|
||||
VariantDef::Struct(it) => it.field(db, name),
|
||||
VariantDef::EnumVariant(it) => it.field(db, name),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn module(self, db: &impl HirDatabase) -> Module {
|
||||
match self {
|
||||
VariantDef::Struct(it) => it.module(db),
|
||||
VariantDef::EnumVariant(it) => it.module(db),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
|
||||
match self {
|
||||
VariantDef::Struct(it) => it.variant_data(db),
|
||||
VariantDef::EnumVariant(it) => it.variant_data(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The defs which have a body.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum DefWithBody {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue