diff options
author | Edwin Cheng <[email protected]> | 2020-05-01 04:23:03 +0100 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2020-05-01 04:23:03 +0100 |
commit | e4267967a8ee3b35d902931cecf06bb4e19f86c5 (patch) | |
tree | 9dc984e821a43da548a70648d1cfc4466d6e1ae9 /crates/ra_hir_def/src/nameres | |
parent | a5f2b16366f027ad60c58266a66eb7fbdcbda9f9 (diff) |
Support local_inner_macros
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 27 |
2 files changed, 23 insertions, 6 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 98c74fe25..bf3968bd6 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -204,6 +204,7 @@ impl DefCollector<'_> { | |||
204 | ast_id: None, | 204 | ast_id: None, |
205 | krate: Some(krate), | 205 | krate: Some(krate), |
206 | kind: MacroDefKind::CustomDerive(expander), | 206 | kind: MacroDefKind::CustomDerive(expander), |
207 | local_inner: false, | ||
207 | }; | 208 | }; |
208 | 209 | ||
209 | self.define_proc_macro(name.clone(), macro_id); | 210 | self.define_proc_macro(name.clone(), macro_id); |
@@ -941,6 +942,7 @@ impl ModCollector<'_, '_> { | |||
941 | ast_id: Some(ast_id.ast_id), | 942 | ast_id: Some(ast_id.ast_id), |
942 | krate: Some(self.def_collector.def_map.krate), | 943 | krate: Some(self.def_collector.def_map.krate), |
943 | kind: MacroDefKind::Declarative, | 944 | kind: MacroDefKind::Declarative, |
945 | local_inner: mac.local_inner, | ||
944 | }; | 946 | }; |
945 | self.def_collector.define_macro(self.module_id, name.clone(), macro_id, mac.export); | 947 | self.def_collector.define_macro(self.module_id, name.clone(), macro_id, mac.export); |
946 | } | 948 | } |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 39b011ad7..aed9dcc72 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -188,6 +188,7 @@ pub(super) struct MacroData { | |||
188 | pub(super) path: ModPath, | 188 | pub(super) path: ModPath, |
189 | pub(super) name: Option<Name>, | 189 | pub(super) name: Option<Name>, |
190 | pub(super) export: bool, | 190 | pub(super) export: bool, |
191 | pub(super) local_inner: bool, | ||
191 | pub(super) builtin: bool, | 192 | pub(super) builtin: bool, |
192 | } | 193 | } |
193 | 194 | ||
@@ -401,14 +402,28 @@ impl RawItemsCollector { | |||
401 | 402 | ||
402 | let name = m.name().map(|it| it.as_name()); | 403 | let name = m.name().map(|it| it.as_name()); |
403 | let ast_id = self.source_ast_id_map.ast_id(&m); | 404 | let ast_id = self.source_ast_id_map.ast_id(&m); |
404 | // FIXME: cfg_attr | ||
405 | let export = m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "macro_export"); | ||
406 | 405 | ||
407 | // FIXME: cfg_attr | 406 | // FIXME: cfg_attr |
408 | let builtin = | 407 | let export = attrs.by_key("macro_export").exists(); |
409 | m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "rustc_builtin_macro"); | 408 | let local_inner = |
410 | 409 | attrs.by_key("macro_export").tt_values().map(|it| &it.token_trees).flatten().any( | |
411 | let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export, builtin }); | 410 | |it| match it { |
411 | tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => { | ||
412 | ident.text.contains("local_inner_macros") | ||
413 | } | ||
414 | _ => false, | ||
415 | }, | ||
416 | ); | ||
417 | let builtin = attrs.by_key("rustc_builtin_macro").exists(); | ||
418 | |||
419 | let m = self.raw_items.macros.alloc(MacroData { | ||
420 | ast_id, | ||
421 | path, | ||
422 | name, | ||
423 | export, | ||
424 | local_inner, | ||
425 | builtin, | ||
426 | }); | ||
412 | self.push_item(current_module, attrs, RawItemKind::Macro(m)); | 427 | self.push_item(current_module, attrs, RawItemKind::Macro(m)); |
413 | } | 428 | } |
414 | 429 | ||