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/diagnostics.rs | |
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/diagnostics.rs')
-rw-r--r-- | crates/ra_hir/src/diagnostics.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs index d41525779..4b7b2dbee 100644 --- a/crates/ra_hir/src/diagnostics.rs +++ b/crates/ra_hir/src/diagnostics.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::{fmt, any::Any}; | 1 | use std::{fmt, any::Any}; |
2 | 2 | ||
3 | use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode, AstNode}; | 3 | use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode}; |
4 | use relative_path::RelativePathBuf; | 4 | use relative_path::RelativePathBuf; |
5 | 5 | ||
6 | use crate::{HirFileId, HirDatabase, Name}; | 6 | use crate::{HirFileId, HirDatabase, Name}; |
@@ -29,8 +29,8 @@ pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { | |||
29 | 29 | ||
30 | impl dyn Diagnostic { | 30 | impl dyn Diagnostic { |
31 | pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> { | 31 | pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> { |
32 | let source_file = db.hir_parse(self.file()); | 32 | let node = db.parse_or_expand(self.file()).unwrap(); |
33 | self.syntax_node_ptr().to_node(source_file.syntax()).to_owned() | 33 | self.syntax_node_ptr().to_node(&*node).to_owned() |
34 | } | 34 | } |
35 | pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { | 35 | pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { |
36 | self.as_any().downcast_ref() | 36 | self.as_any().downcast_ref() |