diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-12 00:05:07 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-12 00:05:07 +0100 |
commit | 9a431c26f4528e2649de0ca171a38c93e473c94e (patch) | |
tree | 191386e03f2975d927a093cc54bab52f37a7cbdf /crates | |
parent | c6e2ba43bbfef80d4ecabbc9edd5be9d058f6db9 (diff) | |
parent | e78221bc58a050e8651f5be591561e7adf89c371 (diff) |
Merge #8808
8808: fix: Fix fn proc macro input again r=jonas-schievink a=jonas-schievink
https://github.com/rust-analyzer/rust-analyzer/pull/8806 broke the `TokenMap`, so none of the tokens in fn-like proc macro inputs could be related to the output (presumably this is because of the `clone_for_update`).
This PR instead just sets `delimiter = None;` after the `TokenMap` and `Subtree` are already created.
We should probably have more tests for fn-like proc macros, and consider making the behavior consistent with MBE (which *require* the delimiters to be present).
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_expand/src/db.rs | 11 | ||||
-rw-r--r-- | crates/hir_expand/src/input.rs | 31 |
2 files changed, 12 insertions, 30 deletions
diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs index 9fa419fcf..c43d382ad 100644 --- a/crates/hir_expand/src/db.rs +++ b/crates/hir_expand/src/db.rs | |||
@@ -267,7 +267,16 @@ fn parse_macro_expansion( | |||
267 | 267 | ||
268 | fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> { | 268 | fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> { |
269 | let arg = db.macro_arg_text(id)?; | 269 | let arg = db.macro_arg_text(id)?; |
270 | let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg)); | 270 | let (mut tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg)); |
271 | |||
272 | if let MacroCallId::LazyMacro(id) = id { | ||
273 | let loc: MacroCallLoc = db.lookup_intern_macro(id); | ||
274 | if loc.def.is_proc_macro() { | ||
275 | // proc macros expect their inputs without parentheses, MBEs expect it with them included | ||
276 | tt.delimiter = None; | ||
277 | } | ||
278 | } | ||
279 | |||
271 | Some(Arc::new((tt, tmap))) | 280 | Some(Arc::new((tt, tmap))) |
272 | } | 281 | } |
273 | 282 | ||
diff --git a/crates/hir_expand/src/input.rs b/crates/hir_expand/src/input.rs index 860aa049b..112216859 100644 --- a/crates/hir_expand/src/input.rs +++ b/crates/hir_expand/src/input.rs | |||
@@ -1,9 +1,8 @@ | |||
1 | //! Macro input conditioning. | 1 | //! Macro input conditioning. |
2 | 2 | ||
3 | use parser::SyntaxKind; | ||
4 | use syntax::{ | 3 | use syntax::{ |
5 | ast::{self, AttrsOwner}, | 4 | ast::{self, AttrsOwner}, |
6 | AstNode, SyntaxElement, SyntaxNode, | 5 | AstNode, SyntaxNode, |
7 | }; | 6 | }; |
8 | 7 | ||
9 | use crate::{ | 8 | use crate::{ |
@@ -20,33 +19,7 @@ pub(crate) fn process_macro_input( | |||
20 | let loc: MacroCallLoc = db.lookup_intern_macro(id); | 19 | let loc: MacroCallLoc = db.lookup_intern_macro(id); |
21 | 20 | ||
22 | match loc.kind { | 21 | match loc.kind { |
23 | MacroCallKind::FnLike { .. } => { | 22 | MacroCallKind::FnLike { .. } => node, |
24 | if !loc.def.is_proc_macro() { | ||
25 | // MBE macros expect the parentheses as part of their input. | ||
26 | return node; | ||
27 | } | ||
28 | |||
29 | // The input includes the `(` + `)` delimiter tokens, so remove them before passing this | ||
30 | // to the macro. | ||
31 | let node = node.clone_for_update(); | ||
32 | if let Some(SyntaxElement::Token(tkn)) = node.first_child_or_token() { | ||
33 | if matches!( | ||
34 | tkn.kind(), | ||
35 | SyntaxKind::L_BRACK | SyntaxKind::L_PAREN | SyntaxKind::L_CURLY | ||
36 | ) { | ||
37 | tkn.detach(); | ||
38 | } | ||
39 | } | ||
40 | if let Some(SyntaxElement::Token(tkn)) = node.last_child_or_token() { | ||
41 | if matches!( | ||
42 | tkn.kind(), | ||
43 | SyntaxKind::R_BRACK | SyntaxKind::R_PAREN | SyntaxKind::R_CURLY | ||
44 | ) { | ||
45 | tkn.detach(); | ||
46 | } | ||
47 | } | ||
48 | node | ||
49 | } | ||
50 | MacroCallKind::Derive { derive_attr_index, .. } => { | 23 | MacroCallKind::Derive { derive_attr_index, .. } => { |
51 | let item = match ast::Item::cast(node.clone()) { | 24 | let item = match ast::Item::cast(node.clone()) { |
52 | Some(item) => item, | 25 | Some(item) => item, |