diff options
Diffstat (limited to 'crates/ra_hir_def/src/attr.rs')
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index 714a66b02..5a86af8ba 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -13,7 +13,8 @@ use ra_syntax::{ | |||
13 | use tt::Subtree; | 13 | use tt::Subtree; |
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
16 | db::DefDatabase, path::ModPath, src::HasChildSource, src::HasSource, AdtId, AttrDefId, Lookup, | 16 | db::DefDatabase, nameres::ModuleSource, path::ModPath, src::HasChildSource, src::HasSource, |
17 | AdtId, AttrDefId, Lookup, | ||
17 | }; | 18 | }; |
18 | 19 | ||
19 | #[derive(Default, Debug, Clone, PartialEq, Eq)] | 20 | #[derive(Default, Debug, Clone, PartialEq, Eq)] |
@@ -37,11 +38,19 @@ impl Attrs { | |||
37 | match def { | 38 | match def { |
38 | AttrDefId::ModuleId(module) => { | 39 | AttrDefId::ModuleId(module) => { |
39 | let def_map = db.crate_def_map(module.krate); | 40 | let def_map = db.crate_def_map(module.krate); |
40 | let src = match def_map[module.local_id].declaration_source(db) { | 41 | let mod_data = &def_map[module.local_id]; |
41 | Some(it) => it, | 42 | match mod_data.declaration_source(db) { |
42 | None => return Attrs::default(), | 43 | Some(it) => { |
43 | }; | 44 | Attrs::from_attrs_owner(db, it.as_ref().map(|it| it as &dyn AttrsOwner)) |
44 | Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) | 45 | } |
46 | None => Attrs::from_attrs_owner( | ||
47 | db, | ||
48 | mod_data.definition_source(db).as_ref().map(|src| match src { | ||
49 | ModuleSource::SourceFile(file) => file as &dyn AttrsOwner, | ||
50 | ModuleSource::Module(module) => module as &dyn AttrsOwner, | ||
51 | }), | ||
52 | ), | ||
53 | } | ||
45 | } | 54 | } |
46 | AttrDefId::FieldId(it) => { | 55 | AttrDefId::FieldId(it) => { |
47 | let src = it.parent.child_source(db); | 56 | let src = it.parent.child_source(db); |
@@ -106,7 +115,9 @@ pub struct Attr { | |||
106 | 115 | ||
107 | #[derive(Debug, Clone, PartialEq, Eq)] | 116 | #[derive(Debug, Clone, PartialEq, Eq)] |
108 | pub enum AttrInput { | 117 | pub enum AttrInput { |
118 | /// `#[attr = "string"]` | ||
109 | Literal(SmolStr), | 119 | Literal(SmolStr), |
120 | /// `#[attr(subtree)]` | ||
110 | TokenTree(Subtree), | 121 | TokenTree(Subtree), |
111 | } | 122 | } |
112 | 123 | ||