diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model/attrs.rs | 25 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/type_alias.rs | 31 |
5 files changed, 19 insertions, 56 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 5690040a7..72c9b466f 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -937,7 +937,7 @@ impl TypeAlias { | |||
937 | } | 937 | } |
938 | 938 | ||
939 | pub fn type_ref(self, db: &impl DefDatabase) -> Option<TypeRef> { | 939 | pub fn type_ref(self, db: &impl DefDatabase) -> Option<TypeRef> { |
940 | db.type_alias_data(self).type_ref.clone() | 940 | db.type_alias_data(self.id).type_ref.clone() |
941 | } | 941 | } |
942 | 942 | ||
943 | pub fn ty(self, db: &impl HirDatabase) -> Ty { | 943 | pub fn ty(self, db: &impl HirDatabase) -> Ty { |
@@ -945,7 +945,7 @@ impl TypeAlias { | |||
945 | } | 945 | } |
946 | 946 | ||
947 | pub fn name(self, db: &impl DefDatabase) -> Name { | 947 | pub fn name(self, db: &impl DefDatabase) -> Name { |
948 | db.type_alias_data(self).name.clone() | 948 | db.type_alias_data(self.id).name.clone() |
949 | } | 949 | } |
950 | } | 950 | } |
951 | 951 | ||
diff --git a/crates/ra_hir/src/code_model/attrs.rs b/crates/ra_hir/src/code_model/attrs.rs index 9e304217c..96da8c88c 100644 --- a/crates/ra_hir/src/code_model/attrs.rs +++ b/crates/ra_hir/src/code_model/attrs.rs | |||
@@ -5,10 +5,9 @@ use crate::{ | |||
5 | Adt, Const, Enum, EnumVariant, FieldSource, Function, HasSource, MacroDef, Module, Static, | 5 | Adt, Const, Enum, EnumVariant, FieldSource, Function, HasSource, MacroDef, Module, Static, |
6 | Struct, StructField, Trait, TypeAlias, Union, | 6 | Struct, StructField, Trait, TypeAlias, Union, |
7 | }; | 7 | }; |
8 | use hir_def::attr::Attr; | 8 | use hir_def::attr::{Attr, Attrs}; |
9 | use hir_expand::hygiene::Hygiene; | 9 | use hir_expand::hygiene::Hygiene; |
10 | use ra_syntax::ast; | 10 | use ra_syntax::ast; |
11 | use std::sync::Arc; | ||
12 | 11 | ||
13 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 12 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
14 | pub enum AttrDef { | 13 | pub enum AttrDef { |
@@ -37,17 +36,17 @@ impl_froms!( | |||
37 | MacroDef | 36 | MacroDef |
38 | ); | 37 | ); |
39 | 38 | ||
40 | pub trait Attrs { | 39 | pub trait HasAttrs { |
41 | fn attrs(&self, db: &impl HirDatabase) -> Option<Arc<[Attr]>>; | 40 | fn attrs(&self, db: &impl HirDatabase) -> Attrs; |
42 | } | 41 | } |
43 | 42 | ||
44 | pub(crate) fn attributes_query( | 43 | pub(crate) fn attributes_query(db: &(impl DefDatabase + AstDatabase), def: AttrDef) -> Attrs { |
45 | db: &(impl DefDatabase + AstDatabase), | ||
46 | def: AttrDef, | ||
47 | ) -> Option<Arc<[Attr]>> { | ||
48 | match def { | 44 | match def { |
49 | AttrDef::Module(it) => { | 45 | AttrDef::Module(it) => { |
50 | let src = it.declaration_source(db)?; | 46 | let src = match it.declaration_source(db) { |
47 | Some(it) => it, | ||
48 | None => return Attrs::default(), | ||
49 | }; | ||
51 | let hygiene = Hygiene::new(db, src.file_id); | 50 | let hygiene = Hygiene::new(db, src.file_id); |
52 | Attr::from_attrs_owner(&src.value, &hygiene) | 51 | Attr::from_attrs_owner(&src.value, &hygiene) |
53 | } | 52 | } |
@@ -57,7 +56,7 @@ pub(crate) fn attributes_query( | |||
57 | let hygiene = Hygiene::new(db, src.file_id); | 56 | let hygiene = Hygiene::new(db, src.file_id); |
58 | Attr::from_attrs_owner(&named, &hygiene) | 57 | Attr::from_attrs_owner(&named, &hygiene) |
59 | } | 58 | } |
60 | FieldSource::Pos(..) => None, | 59 | FieldSource::Pos(..) => Attrs::default(), |
61 | }, | 60 | }, |
62 | AttrDef::Adt(it) => match it { | 61 | AttrDef::Adt(it) => match it { |
63 | Adt::Struct(it) => attrs_from_ast(it, db), | 62 | Adt::Struct(it) => attrs_from_ast(it, db), |
@@ -74,7 +73,7 @@ pub(crate) fn attributes_query( | |||
74 | } | 73 | } |
75 | } | 74 | } |
76 | 75 | ||
77 | fn attrs_from_ast<T, D>(node: T, db: &D) -> Option<Arc<[Attr]>> | 76 | fn attrs_from_ast<T, D>(node: T, db: &D) -> Attrs |
78 | where | 77 | where |
79 | T: HasSource, | 78 | T: HasSource, |
80 | T::Ast: ast::AttrsOwner, | 79 | T::Ast: ast::AttrsOwner, |
@@ -85,8 +84,8 @@ where | |||
85 | Attr::from_attrs_owner(&src.value, &hygiene) | 84 | Attr::from_attrs_owner(&src.value, &hygiene) |
86 | } | 85 | } |
87 | 86 | ||
88 | impl<T: Into<AttrDef> + Copy> Attrs for T { | 87 | impl<T: Into<AttrDef> + Copy> HasAttrs for T { |
89 | fn attrs(&self, db: &impl HirDatabase) -> Option<Arc<[Attr]>> { | 88 | fn attrs(&self, db: &impl HirDatabase) -> Attrs { |
90 | db.attrs((*self).into()) | 89 | db.attrs((*self).into()) |
91 | } | 90 | } |
92 | } | 91 | } |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index ed0d68001..1cfcb2fd2 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_def::attr::Attr; | 5 | use hir_def::attr::Attrs; |
6 | use ra_db::salsa; | 6 | use ra_db::salsa; |
7 | use ra_syntax::SmolStr; | 7 | use ra_syntax::SmolStr; |
8 | 8 | ||
@@ -16,16 +16,15 @@ use crate::{ | |||
16 | CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef, | 16 | CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef, |
17 | TypeCtor, | 17 | TypeCtor, |
18 | }, | 18 | }, |
19 | type_alias::TypeAliasData, | ||
20 | Const, ConstData, Crate, DefWithBody, FnData, Function, GenericDef, ImplBlock, Module, Static, | 19 | Const, ConstData, Crate, DefWithBody, FnData, Function, GenericDef, ImplBlock, Module, Static, |
21 | StructField, Trait, TypeAlias, | 20 | StructField, Trait, |
22 | }; | 21 | }; |
23 | 22 | ||
24 | pub use hir_def::db::{ | 23 | pub use hir_def::db::{ |
25 | BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage, | 24 | BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage, |
26 | EnumDataQuery, ExprScopesQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, | 25 | EnumDataQuery, ExprScopesQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, |
27 | InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery, | 26 | InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery, |
28 | TraitDataQuery, | 27 | TraitDataQuery, TypeAliasDataQuery, |
29 | }; | 28 | }; |
30 | pub use hir_expand::db::{ | 29 | pub use hir_expand::db::{ |
31 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, | 30 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, |
@@ -39,9 +38,6 @@ pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { | |||
39 | #[salsa::invoke(FnData::fn_data_query)] | 38 | #[salsa::invoke(FnData::fn_data_query)] |
40 | fn fn_data(&self, func: Function) -> Arc<FnData>; | 39 | fn fn_data(&self, func: Function) -> Arc<FnData>; |
41 | 40 | ||
42 | #[salsa::invoke(TypeAliasData::type_alias_data_query)] | ||
43 | fn type_alias_data(&self, typ: TypeAlias) -> Arc<TypeAliasData>; | ||
44 | |||
45 | #[salsa::invoke(ConstData::const_data_query)] | 41 | #[salsa::invoke(ConstData::const_data_query)] |
46 | fn const_data(&self, konst: Const) -> Arc<ConstData>; | 42 | fn const_data(&self, konst: Const) -> Arc<ConstData>; |
47 | 43 | ||
@@ -61,7 +57,7 @@ pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { | |||
61 | fn documentation(&self, def: crate::DocDef) -> Option<crate::Documentation>; | 57 | fn documentation(&self, def: crate::DocDef) -> Option<crate::Documentation>; |
62 | 58 | ||
63 | #[salsa::invoke(crate::code_model::attrs::attributes_query)] | 59 | #[salsa::invoke(crate::code_model::attrs::attributes_query)] |
64 | fn attrs(&self, def: crate::AttrDef) -> Option<Arc<[Attr]>>; | 60 | fn attrs(&self, def: crate::AttrDef) -> Attrs; |
65 | } | 61 | } |
66 | 62 | ||
67 | #[salsa::query_group(HirDatabaseStorage)] | 63 | #[salsa::query_group(HirDatabaseStorage)] |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 8c6834392..8535629ca 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 type_alias; | ||
36 | mod ty; | 35 | mod ty; |
37 | mod impl_block; | 36 | mod impl_block; |
38 | mod expr; | 37 | mod expr; |
@@ -52,7 +51,7 @@ mod marks; | |||
52 | 51 | ||
53 | pub use crate::{ | 52 | pub use crate::{ |
54 | code_model::{ | 53 | code_model::{ |
55 | attrs::{AttrDef, Attrs}, | 54 | attrs::{AttrDef, HasAttrs}, |
56 | docs::{DocDef, Docs, Documentation}, | 55 | docs::{DocDef, Docs, Documentation}, |
57 | src::{HasBodySource, HasSource}, | 56 | src::{HasBodySource, HasSource}, |
58 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, | 57 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, |
diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs deleted file mode 100644 index 392f244cf..000000000 --- a/crates/ra_hir/src/type_alias.rs +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | //! HIR for type aliases (i.e. the `type` keyword). | ||
2 | |||
3 | use std::sync::Arc; | ||
4 | |||
5 | use hir_def::type_ref::TypeRef; | ||
6 | use hir_expand::name::{AsName, Name}; | ||
7 | |||
8 | use ra_syntax::ast::NameOwner; | ||
9 | |||
10 | use crate::{ | ||
11 | db::{AstDatabase, DefDatabase}, | ||
12 | HasSource, TypeAlias, | ||
13 | }; | ||
14 | |||
15 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
16 | pub struct TypeAliasData { | ||
17 | pub(crate) name: Name, | ||
18 | pub(crate) type_ref: Option<TypeRef>, | ||
19 | } | ||
20 | |||
21 | impl TypeAliasData { | ||
22 | pub(crate) fn type_alias_data_query( | ||
23 | db: &(impl DefDatabase + AstDatabase), | ||
24 | typ: TypeAlias, | ||
25 | ) -> Arc<TypeAliasData> { | ||
26 | let node = typ.source(db).value; | ||
27 | let name = node.name().map_or_else(Name::missing, |n| n.as_name()); | ||
28 | let type_ref = node.type_ref().map(TypeRef::from_ast); | ||
29 | Arc::new(TypeAliasData { name, type_ref }) | ||
30 | } | ||
31 | } | ||