diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-22 09:27:13 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-22 09:27:13 +0000 |
commit | f24aa7a45ad6ffbbae56d5bca50afd6aefa1a4c7 (patch) | |
tree | 286d7f91a45aa132691729a98302b687f677b643 /crates/ra_hir/src/code_model/attrs.rs | |
parent | d59bf33b9e1c20d6ef3fd9b72f3cf4730172b5a8 (diff) | |
parent | a87e9145a67634a5ea8a893ab8b52b3c07108a13 (diff) |
Merge #2351
2351: Rename Atts trait r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model/attrs.rs')
-rw-r--r-- | crates/ra_hir/src/code_model/attrs.rs | 25 |
1 files changed, 12 insertions, 13 deletions
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 | } |