diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-14 07:12:09 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-14 07:12:09 +0100 |
commit | c417c77b681f10cc7585507bd874e9fd2cea63b8 (patch) | |
tree | d05cf30716a7791cfc0d8fcfe522a7132b5fff06 /crates/ra_hir/src/nameres | |
parent | ee0ab7c00b4b8c5375c14b44e3d7288ebf0d732d (diff) | |
parent | caa8663c08e1724af2abcde11fa937937d76aa14 (diff) |
Merge #1267
1267: Macro expand to r=edwin0cheng a=matklad
closes #1264
The core problem this PR is trying to wrangle is that macros can expand to different stuffs, depending on context.
That is, `foo!()` on the top-level expands to a list of items, but the same `foo!()` in expression position expands to expression.
Our current `hir_parse(HirFileId) -> TreeArc<SourceFile>` does not really support this.
So, the plan is to change `hir_parse` to untyped inreface (`TreeArc<Syntaxnode>`), and add `expands_to` field to `MacroCallLoc`, such that the *target* of macro expansion is selected by the calling code and is part of macro id.
This unfortunately looses some type-safety :(
Moreover, this doesn't really fix #1264 by itself, because we die due to some other error inside macro expansion: expander fails to produce a tree with a single root, which trips assert inside rowan.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/raw.rs | 7 |
2 files changed, 7 insertions, 4 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 4640b3b74..c615d80c3 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -15,7 +15,7 @@ use crate::{ | |||
15 | diagnostics::DefDiagnostic, | 15 | diagnostics::DefDiagnostic, |
16 | raw, | 16 | raw, |
17 | }, | 17 | }, |
18 | ids::{AstItemDef, LocationCtx, MacroCallLoc, MacroCallId, MacroDefId}, | 18 | ids::{AstItemDef, LocationCtx, MacroCallLoc, MacroCallId, MacroDefId, MacroFileKind}, |
19 | AstId, | 19 | AstId, |
20 | }; | 20 | }; |
21 | 21 | ||
@@ -371,7 +371,7 @@ where | |||
371 | self.macro_stack_monitor.increase(macro_def_id); | 371 | self.macro_stack_monitor.increase(macro_def_id); |
372 | 372 | ||
373 | if !self.macro_stack_monitor.is_poison(macro_def_id) { | 373 | if !self.macro_stack_monitor.is_poison(macro_def_id) { |
374 | let file_id: HirFileId = macro_call_id.into(); | 374 | let file_id: HirFileId = macro_call_id.as_file(MacroFileKind::Items); |
375 | let raw_items = self.db.raw_items(file_id); | 375 | let raw_items = self.db.raw_items(file_id); |
376 | ModCollector { def_collector: &mut *self, file_id, module_id, raw_items: &raw_items } | 376 | ModCollector { def_collector: &mut *self, file_id, module_id, raw_items: &raw_items } |
377 | .collect(raw_items.items()); | 377 | .collect(raw_items.items()); |
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 211e02068..bd32b264b 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs | |||
@@ -75,8 +75,11 @@ impl RawItems { | |||
75 | source_ast_id_map: db.ast_id_map(file_id.into()), | 75 | source_ast_id_map: db.ast_id_map(file_id.into()), |
76 | source_map: ImportSourceMap::default(), | 76 | source_map: ImportSourceMap::default(), |
77 | }; | 77 | }; |
78 | let source_file = db.hir_parse(file_id); | 78 | if let Some(node) = db.parse_or_expand(file_id) { |
79 | collector.process_module(None, &*source_file); | 79 | if let Some(source_file) = ast::SourceFile::cast(&node) { |
80 | collector.process_module(None, &*source_file); | ||
81 | } | ||
82 | } | ||
80 | (Arc::new(collector.raw_items), Arc::new(collector.source_map)) | 83 | (Arc::new(collector.raw_items), Arc::new(collector.source_map)) |
81 | } | 84 | } |
82 | 85 | ||