diff options
Diffstat (limited to 'crates/ra_hir_expand/src/hygiene.rs')
-rw-r--r-- | crates/ra_hir_expand/src/hygiene.rs | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/crates/ra_hir_expand/src/hygiene.rs b/crates/ra_hir_expand/src/hygiene.rs index 0b41d0e95..6b482a60c 100644 --- a/crates/ra_hir_expand/src/hygiene.rs +++ b/crates/ra_hir_expand/src/hygiene.rs | |||
@@ -12,35 +12,38 @@ use crate::{ | |||
12 | HirFileId, HirFileIdRepr, MacroCallId, MacroDefKind, | 12 | HirFileId, HirFileIdRepr, MacroCallId, MacroDefKind, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | #[derive(Debug)] | 15 | #[derive(Clone, Debug)] |
16 | pub struct Hygiene { | 16 | pub struct Hygiene { |
17 | // This is what `$crate` expands to | 17 | // This is what `$crate` expands to |
18 | def_crate: Option<CrateId>, | 18 | def_crate: Option<CrateId>, |
19 | |||
20 | // Indiciate this is a local inner macro | ||
21 | local_inner: bool, | ||
19 | } | 22 | } |
20 | 23 | ||
21 | impl Hygiene { | 24 | impl Hygiene { |
22 | pub fn new(db: &dyn AstDatabase, file_id: HirFileId) -> Hygiene { | 25 | pub fn new(db: &dyn AstDatabase, file_id: HirFileId) -> Hygiene { |
23 | let def_crate = match file_id.0 { | 26 | let (def_crate, local_inner) = match file_id.0 { |
24 | HirFileIdRepr::FileId(_) => None, | 27 | HirFileIdRepr::FileId(_) => (None, false), |
25 | HirFileIdRepr::MacroFile(macro_file) => match macro_file.macro_call_id { | 28 | HirFileIdRepr::MacroFile(macro_file) => match macro_file.macro_call_id { |
26 | MacroCallId::LazyMacro(id) => { | 29 | MacroCallId::LazyMacro(id) => { |
27 | let loc = db.lookup_intern_macro(id); | 30 | let loc = db.lookup_intern_macro(id); |
28 | match loc.def.kind { | 31 | match loc.def.kind { |
29 | MacroDefKind::Declarative => loc.def.krate, | 32 | MacroDefKind::Declarative => (loc.def.krate, loc.def.local_inner), |
30 | MacroDefKind::BuiltIn(_) => None, | 33 | MacroDefKind::BuiltIn(_) => (None, false), |
31 | MacroDefKind::BuiltInDerive(_) => None, | 34 | MacroDefKind::BuiltInDerive(_) => (None, false), |
32 | MacroDefKind::BuiltInEager(_) => None, | 35 | MacroDefKind::BuiltInEager(_) => (None, false), |
33 | MacroDefKind::CustomDerive(_) => None, | 36 | MacroDefKind::CustomDerive(_) => (None, false), |
34 | } | 37 | } |
35 | } | 38 | } |
36 | MacroCallId::EagerMacro(_id) => None, | 39 | MacroCallId::EagerMacro(_id) => (None, false), |
37 | }, | 40 | }, |
38 | }; | 41 | }; |
39 | Hygiene { def_crate } | 42 | Hygiene { def_crate, local_inner } |
40 | } | 43 | } |
41 | 44 | ||
42 | pub fn new_unhygienic() -> Hygiene { | 45 | pub fn new_unhygienic() -> Hygiene { |
43 | Hygiene { def_crate: None } | 46 | Hygiene { def_crate: None, local_inner: false } |
44 | } | 47 | } |
45 | 48 | ||
46 | // FIXME: this should just return name | 49 | // FIXME: this should just return name |
@@ -52,4 +55,12 @@ impl Hygiene { | |||
52 | } | 55 | } |
53 | Either::Left(name_ref.as_name()) | 56 | Either::Left(name_ref.as_name()) |
54 | } | 57 | } |
58 | |||
59 | pub fn local_inner_macros(&self) -> Option<CrateId> { | ||
60 | if self.local_inner { | ||
61 | self.def_crate | ||
62 | } else { | ||
63 | None | ||
64 | } | ||
65 | } | ||
55 | } | 66 | } |