aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/adt.rs54
-rw-r--r--crates/ra_hir/src/code_model.rs42
-rw-r--r--crates/ra_hir/src/code_model/src.rs3
-rw-r--r--crates/ra_hir/src/lib.rs8
-rw-r--r--crates/ra_hir/src/ty/infer.rs3
-rw-r--r--crates/ra_hir/src/ty/lower.rs3
6 files changed, 47 insertions, 66 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
deleted file mode 100644
index 945f236c2..000000000
--- a/crates/ra_hir/src/adt.rs
+++ /dev/null
@@ -1,54 +0,0 @@
1//! This module contains the implementation details of the HIR for ADTs, i.e.
2//! structs and enums (and unions).
3
4use std::sync::Arc;
5
6use hir_def::adt::VariantData;
7
8use crate::{
9 db::{DefDatabase, HirDatabase},
10 EnumVariant, Module, Name, Struct, StructField,
11};
12
13impl Struct {
14 pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
15 db.struct_data(self.id.into()).variant_data.clone()
16 }
17}
18
19#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
20pub enum VariantDef {
21 Struct(Struct),
22 EnumVariant(EnumVariant),
23}
24impl_froms!(VariantDef: Struct, EnumVariant);
25
26impl VariantDef {
27 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> {
28 match self {
29 VariantDef::Struct(it) => it.fields(db),
30 VariantDef::EnumVariant(it) => it.fields(db),
31 }
32 }
33
34 pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> {
35 match self {
36 VariantDef::Struct(it) => it.field(db, name),
37 VariantDef::EnumVariant(it) => it.field(db, name),
38 }
39 }
40
41 pub fn module(self, db: &impl HirDatabase) -> Module {
42 match self {
43 VariantDef::Struct(it) => it.module(db),
44 VariantDef::EnumVariant(it) => it.module(db),
45 }
46 }
47
48 pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
49 match self {
50 VariantDef::Struct(it) => it.variant_data(db),
51 VariantDef::EnumVariant(it) => it.variant_data(db),
52 }
53 }
54}
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};
23use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; 23use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
24 24
25use crate::{ 25use 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)]
489pub enum VariantDef {
490 Struct(Struct),
491 EnumVariant(EnumVariant),
492}
493impl_froms!(VariantDef: Struct, EnumVariant);
494
495impl 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)]
487pub enum DefWithBody { 527pub enum DefWithBody {
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index 354d2c98f..4aa427de4 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -4,11 +4,10 @@ use hir_def::{HasSource as _, Lookup};
4use ra_syntax::ast::{self, AstNode}; 4use ra_syntax::ast::{self, AstNode};
5 5
6use crate::{ 6use crate::{
7 adt::VariantDef,
8 db::{AstDatabase, DefDatabase, HirDatabase}, 7 db::{AstDatabase, DefDatabase, HirDatabase},
9 ids::AstItemDef, 8 ids::AstItemDef,
10 Const, Either, Enum, EnumVariant, FieldSource, Function, HasBody, HirFileId, MacroDef, Module, 9 Const, Either, Enum, EnumVariant, FieldSource, Function, HasBody, HirFileId, MacroDef, Module,
11 ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, 10 ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef,
12}; 11};
13 12
14pub use hir_expand::Source; 13pub use hir_expand::Source;
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 7ac9a9041..31da74d2f 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -32,7 +32,6 @@ pub mod db;
32pub mod source_binder; 32pub mod source_binder;
33 33
34mod ids; 34mod ids;
35mod adt;
36mod type_alias; 35mod type_alias;
37mod ty; 36mod ty;
38mod impl_block; 37mod impl_block;
@@ -56,15 +55,14 @@ mod marks;
56use crate::resolve::Resolver; 55use crate::resolve::Resolver;
57 56
58pub use crate::{ 57pub use crate::{
59 adt::VariantDef,
60 code_model::ImplBlock,
61 code_model::{ 58 code_model::{
62 attrs::{AttrDef, Attrs}, 59 attrs::{AttrDef, Attrs},
63 docs::{DocDef, Docs, Documentation}, 60 docs::{DocDef, Docs, Documentation},
64 src::{HasBodySource, HasSource}, 61 src::{HasBodySource, HasSource},
65 Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, 62 Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
66 EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, Local, MacroDef, Module, 63 EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, ImplBlock, Local,
67 ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, 64 MacroDef, Module, ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias,
65 Union, VariantDef,
68 }, 66 },
69 expr::ExprScopes, 67 expr::ExprScopes,
70 from_source::FromSource, 68 from_source::FromSource,
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index c35378cc4..092bc3a3f 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -37,14 +37,13 @@ use super::{
37 TypeCtor, TypeWalk, Uncertain, 37 TypeCtor, TypeWalk, Uncertain,
38}; 38};
39use crate::{ 39use crate::{
40 adt::VariantDef,
41 code_model::TypeAlias, 40 code_model::TypeAlias,
42 db::HirDatabase, 41 db::HirDatabase,
43 expr::{BindingAnnotation, Body, ExprId, PatId}, 42 expr::{BindingAnnotation, Body, ExprId, PatId},
44 resolve::{Resolver, TypeNs}, 43 resolve::{Resolver, TypeNs},
45 ty::infer::diagnostics::InferenceDiagnostic, 44 ty::infer::diagnostics::InferenceDiagnostic,
46 Adt, AssocItem, ConstData, DefWithBody, FloatTy, FnData, Function, HasBody, IntTy, Path, 45 Adt, AssocItem, ConstData, DefWithBody, FloatTy, FnData, Function, HasBody, IntTy, Path,
47 StructField, 46 StructField, VariantDef,
48}; 47};
49 48
50macro_rules! ty_app { 49macro_rules! ty_app {
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 03db38605..91e60b5ab 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -19,7 +19,6 @@ use super::{
19 TypeWalk, 19 TypeWalk,
20}; 20};
21use crate::{ 21use crate::{
22 adt::VariantDef,
23 db::HirDatabase, 22 db::HirDatabase,
24 generics::HasGenericParams, 23 generics::HasGenericParams,
25 generics::{GenericDef, WherePredicate}, 24 generics::{GenericDef, WherePredicate},
@@ -30,7 +29,7 @@ use crate::{
30 }, 29 },
31 util::make_mut_slice, 30 util::make_mut_slice,
32 Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait, 31 Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait,
33 TypeAlias, Union, 32 TypeAlias, Union, VariantDef,
34}; 33};
35 34
36// FIXME: this is only really used in `type_for_def`, which contains a bunch of 35// FIXME: this is only really used in `type_for_def`, which contains a bunch of