diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model/attrs.rs | 21 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 |
2 files changed, 10 insertions, 13 deletions
diff --git a/crates/ra_hir/src/code_model/attrs.rs b/crates/ra_hir/src/code_model/attrs.rs index 9923cde81..96da8c88c 100644 --- a/crates/ra_hir/src/code_model/attrs.rs +++ b/crates/ra_hir/src/code_model/attrs.rs | |||
@@ -5,7 +5,7 @@ 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 | 11 | ||
@@ -36,19 +36,16 @@ impl_froms!( | |||
36 | MacroDef | 36 | MacroDef |
37 | ); | 37 | ); |
38 | 38 | ||
39 | pub trait Attrs { | 39 | pub trait HasAttrs { |
40 | fn attrs(&self, db: &impl HirDatabase) -> hir_def::attr::Attrs; | 40 | fn attrs(&self, db: &impl HirDatabase) -> Attrs; |
41 | } | 41 | } |
42 | 42 | ||
43 | pub(crate) fn attributes_query( | 43 | pub(crate) fn attributes_query(db: &(impl DefDatabase + AstDatabase), def: AttrDef) -> Attrs { |
44 | db: &(impl DefDatabase + AstDatabase), | ||
45 | def: AttrDef, | ||
46 | ) -> hir_def::attr::Attrs { | ||
47 | match def { | 44 | match def { |
48 | AttrDef::Module(it) => { | 45 | AttrDef::Module(it) => { |
49 | let src = match it.declaration_source(db) { | 46 | let src = match it.declaration_source(db) { |
50 | Some(it) => it, | 47 | Some(it) => it, |
51 | None => return hir_def::attr::Attrs::default(), | 48 | None => return Attrs::default(), |
52 | }; | 49 | }; |
53 | let hygiene = Hygiene::new(db, src.file_id); | 50 | let hygiene = Hygiene::new(db, src.file_id); |
54 | Attr::from_attrs_owner(&src.value, &hygiene) | 51 | Attr::from_attrs_owner(&src.value, &hygiene) |
@@ -59,7 +56,7 @@ pub(crate) fn attributes_query( | |||
59 | let hygiene = Hygiene::new(db, src.file_id); | 56 | let hygiene = Hygiene::new(db, src.file_id); |
60 | Attr::from_attrs_owner(&named, &hygiene) | 57 | Attr::from_attrs_owner(&named, &hygiene) |
61 | } | 58 | } |
62 | FieldSource::Pos(..) => hir_def::attr::Attrs::default(), | 59 | FieldSource::Pos(..) => Attrs::default(), |
63 | }, | 60 | }, |
64 | AttrDef::Adt(it) => match it { | 61 | AttrDef::Adt(it) => match it { |
65 | Adt::Struct(it) => attrs_from_ast(it, db), | 62 | Adt::Struct(it) => attrs_from_ast(it, db), |
@@ -76,7 +73,7 @@ pub(crate) fn attributes_query( | |||
76 | } | 73 | } |
77 | } | 74 | } |
78 | 75 | ||
79 | fn attrs_from_ast<T, D>(node: T, db: &D) -> hir_def::attr::Attrs | 76 | fn attrs_from_ast<T, D>(node: T, db: &D) -> Attrs |
80 | where | 77 | where |
81 | T: HasSource, | 78 | T: HasSource, |
82 | T::Ast: ast::AttrsOwner, | 79 | T::Ast: ast::AttrsOwner, |
@@ -87,8 +84,8 @@ where | |||
87 | Attr::from_attrs_owner(&src.value, &hygiene) | 84 | Attr::from_attrs_owner(&src.value, &hygiene) |
88 | } | 85 | } |
89 | 86 | ||
90 | impl<T: Into<AttrDef> + Copy> Attrs for T { | 87 | impl<T: Into<AttrDef> + Copy> HasAttrs for T { |
91 | fn attrs(&self, db: &impl HirDatabase) -> hir_def::attr::Attrs { | 88 | fn attrs(&self, db: &impl HirDatabase) -> Attrs { |
92 | db.attrs((*self).into()) | 89 | db.attrs((*self).into()) |
93 | } | 90 | } |
94 | } | 91 | } |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 8c6834392..915ca46fb 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -52,7 +52,7 @@ mod marks; | |||
52 | 52 | ||
53 | pub use crate::{ | 53 | pub use crate::{ |
54 | code_model::{ | 54 | code_model::{ |
55 | attrs::{AttrDef, Attrs}, | 55 | attrs::{AttrDef, HasAttrs}, |
56 | docs::{DocDef, Docs, Documentation}, | 56 | docs::{DocDef, Docs, Documentation}, |
57 | src::{HasBodySource, HasSource}, | 57 | src::{HasBodySource, HasSource}, |
58 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, | 58 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, |