diff options
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index e2638cf92..9b6276b51 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -23,7 +23,6 @@ use ra_db::{CrateId, Edition}; | |||
23 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 23 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; |
24 | 24 | ||
25 | use crate::{ | 25 | use crate::{ |
26 | adt::VariantDef, | ||
27 | db::{AstDatabase, DefDatabase, HirDatabase}, | 26 | db::{AstDatabase, DefDatabase, HirDatabase}, |
28 | expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, | 27 | expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, |
29 | generics::{GenericDef, HasGenericParams}, | 28 | generics::{GenericDef, HasGenericParams}, |
@@ -324,6 +323,10 @@ impl Struct { | |||
324 | // ...and add generic params, if present | 323 | // ...and add generic params, if present |
325 | r.push_generic_params_scope(db, self.into()) | 324 | r.push_generic_params_scope(db, self.into()) |
326 | } | 325 | } |
326 | |||
327 | fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { | ||
328 | db.struct_data(self.id.into()).variant_data.clone() | ||
329 | } | ||
327 | } | 330 | } |
328 | 331 | ||
329 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 332 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -482,6 +485,43 @@ impl Adt { | |||
482 | } | 485 | } |
483 | } | 486 | } |
484 | 487 | ||
488 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
489 | pub enum VariantDef { | ||
490 | Struct(Struct), | ||
491 | EnumVariant(EnumVariant), | ||
492 | } | ||
493 | impl_froms!(VariantDef: Struct, EnumVariant); | ||
494 | |||
495 | impl VariantDef { | ||
496 | pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { | ||
497 | match self { | ||
498 | VariantDef::Struct(it) => it.fields(db), | ||
499 | VariantDef::EnumVariant(it) => it.fields(db), | ||
500 | } | ||
501 | } | ||
502 | |||
503 | pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> { | ||
504 | match self { | ||
505 | VariantDef::Struct(it) => it.field(db, name), | ||
506 | VariantDef::EnumVariant(it) => it.field(db, name), | ||
507 | } | ||
508 | } | ||
509 | |||
510 | pub fn module(self, db: &impl HirDatabase) -> Module { | ||
511 | match self { | ||
512 | VariantDef::Struct(it) => it.module(db), | ||
513 | VariantDef::EnumVariant(it) => it.module(db), | ||
514 | } | ||
515 | } | ||
516 | |||
517 | pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { | ||
518 | match self { | ||
519 | VariantDef::Struct(it) => it.variant_data(db), | ||
520 | VariantDef::EnumVariant(it) => it.variant_data(db), | ||
521 | } | ||
522 | } | ||
523 | } | ||
524 | |||
485 | /// The defs which have a body. | 525 | /// The defs which have a body. |
486 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 526 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
487 | pub enum DefWithBody { | 527 | pub enum DefWithBody { |