diff options
author | Aleksey Kladov <[email protected]> | 2019-11-20 18:08:39 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-20 18:34:12 +0000 |
commit | 7c275a7ed2253fc7bd8b46c685a754c4d4e9dee3 (patch) | |
tree | 5d26637cbfa8d03ef5f1aed41121ff0db1b75607 /crates/ra_hir/src | |
parent | 12ec946216a3637685f30ae359bc955313595a22 (diff) |
Remove hir/adt.rs
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/adt.rs | 54 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 42 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 3 |
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 | |||
4 | use std::sync::Arc; | ||
5 | |||
6 | use hir_def::adt::VariantData; | ||
7 | |||
8 | use crate::{ | ||
9 | db::{DefDatabase, HirDatabase}, | ||
10 | EnumVariant, Module, Name, Struct, StructField, | ||
11 | }; | ||
12 | |||
13 | impl 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)] | ||
20 | pub enum VariantDef { | ||
21 | Struct(Struct), | ||
22 | EnumVariant(EnumVariant), | ||
23 | } | ||
24 | impl_froms!(VariantDef: Struct, EnumVariant); | ||
25 | |||
26 | impl 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}; | |||
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 { |
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}; | |||
4 | use ra_syntax::ast::{self, AstNode}; | 4 | use ra_syntax::ast::{self, AstNode}; |
5 | 5 | ||
6 | use crate::{ | 6 | use 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 | ||
14 | pub use hir_expand::Source; | 13 | pub 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; | |||
32 | pub mod source_binder; | 32 | pub mod source_binder; |
33 | 33 | ||
34 | mod ids; | 34 | mod ids; |
35 | mod adt; | ||
36 | mod type_alias; | 35 | mod type_alias; |
37 | mod ty; | 36 | mod ty; |
38 | mod impl_block; | 37 | mod impl_block; |
@@ -56,15 +55,14 @@ mod marks; | |||
56 | use crate::resolve::Resolver; | 55 | use crate::resolve::Resolver; |
57 | 56 | ||
58 | pub use crate::{ | 57 | pub 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 | }; |
39 | use crate::{ | 39 | use 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 | ||
50 | macro_rules! ty_app { | 49 | macro_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 | }; |
21 | use crate::{ | 21 | use 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 |