diff options
author | Aleksey Kladov <[email protected]> | 2019-11-22 08:27:47 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-22 08:27:47 +0000 |
commit | e42f9627664cc3c44094e1c4f985270fbfd592b1 (patch) | |
tree | 81603da9c34f301cf82e1ceae80313b8eb9e10c4 /crates/ra_hir/src/code_model/attrs.rs | |
parent | a1346bba5c457d1aa0a35f44231bed8b494b7d60 (diff) |
Encapsulate Attrs
Diffstat (limited to 'crates/ra_hir/src/code_model/attrs.rs')
-rw-r--r-- | crates/ra_hir/src/code_model/attrs.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/crates/ra_hir/src/code_model/attrs.rs b/crates/ra_hir/src/code_model/attrs.rs index 9e304217c..9923cde81 100644 --- a/crates/ra_hir/src/code_model/attrs.rs +++ b/crates/ra_hir/src/code_model/attrs.rs | |||
@@ -8,7 +8,6 @@ use crate::{ | |||
8 | use hir_def::attr::Attr; | 8 | use hir_def::attr::Attr; |
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 { |
@@ -38,16 +37,19 @@ impl_froms!( | |||
38 | ); | 37 | ); |
39 | 38 | ||
40 | pub trait Attrs { | 39 | pub trait Attrs { |
41 | fn attrs(&self, db: &impl HirDatabase) -> Option<Arc<[Attr]>>; | 40 | fn attrs(&self, db: &impl HirDatabase) -> hir_def::attr::Attrs; |
42 | } | 41 | } |
43 | 42 | ||
44 | pub(crate) fn attributes_query( | 43 | pub(crate) fn attributes_query( |
45 | db: &(impl DefDatabase + AstDatabase), | 44 | db: &(impl DefDatabase + AstDatabase), |
46 | def: AttrDef, | 45 | def: AttrDef, |
47 | ) -> Option<Arc<[Attr]>> { | 46 | ) -> hir_def::attr::Attrs { |
48 | match def { | 47 | match def { |
49 | AttrDef::Module(it) => { | 48 | AttrDef::Module(it) => { |
50 | let src = it.declaration_source(db)?; | 49 | let src = match it.declaration_source(db) { |
50 | Some(it) => it, | ||
51 | None => return hir_def::attr::Attrs::default(), | ||
52 | }; | ||
51 | let hygiene = Hygiene::new(db, src.file_id); | 53 | let hygiene = Hygiene::new(db, src.file_id); |
52 | Attr::from_attrs_owner(&src.value, &hygiene) | 54 | Attr::from_attrs_owner(&src.value, &hygiene) |
53 | } | 55 | } |
@@ -57,7 +59,7 @@ pub(crate) fn attributes_query( | |||
57 | let hygiene = Hygiene::new(db, src.file_id); | 59 | let hygiene = Hygiene::new(db, src.file_id); |
58 | Attr::from_attrs_owner(&named, &hygiene) | 60 | Attr::from_attrs_owner(&named, &hygiene) |
59 | } | 61 | } |
60 | FieldSource::Pos(..) => None, | 62 | FieldSource::Pos(..) => hir_def::attr::Attrs::default(), |
61 | }, | 63 | }, |
62 | AttrDef::Adt(it) => match it { | 64 | AttrDef::Adt(it) => match it { |
63 | Adt::Struct(it) => attrs_from_ast(it, db), | 65 | Adt::Struct(it) => attrs_from_ast(it, db), |
@@ -74,7 +76,7 @@ pub(crate) fn attributes_query( | |||
74 | } | 76 | } |
75 | } | 77 | } |
76 | 78 | ||
77 | fn attrs_from_ast<T, D>(node: T, db: &D) -> Option<Arc<[Attr]>> | 79 | fn attrs_from_ast<T, D>(node: T, db: &D) -> hir_def::attr::Attrs |
78 | where | 80 | where |
79 | T: HasSource, | 81 | T: HasSource, |
80 | T::Ast: ast::AttrsOwner, | 82 | T::Ast: ast::AttrsOwner, |
@@ -86,7 +88,7 @@ where | |||
86 | } | 88 | } |
87 | 89 | ||
88 | impl<T: Into<AttrDef> + Copy> Attrs for T { | 90 | impl<T: Into<AttrDef> + Copy> Attrs for T { |
89 | fn attrs(&self, db: &impl HirDatabase) -> Option<Arc<[Attr]>> { | 91 | fn attrs(&self, db: &impl HirDatabase) -> hir_def::attr::Attrs { |
90 | db.attrs((*self).into()) | 92 | db.attrs((*self).into()) |
91 | } | 93 | } |
92 | } | 94 | } |