diff options
-rw-r--r-- | crates/ra_mbe/src/syntax_bridge.rs | 7 | ||||
-rw-r--r-- | crates/ra_mbe/src/tests.rs | 31 |
2 files changed, 35 insertions, 3 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 2aaf0215f..d8ee74faa 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs | |||
@@ -388,11 +388,12 @@ impl<'a> TreeSink for TtTreeSink<'a> { | |||
388 | return; | 388 | return; |
389 | } | 389 | } |
390 | 390 | ||
391 | let mut last = self.cursor; | ||
391 | for _ in 0..n_tokens { | 392 | for _ in 0..n_tokens { |
392 | if self.cursor.eof() { | 393 | if self.cursor.eof() { |
393 | break; | 394 | break; |
394 | } | 395 | } |
395 | 396 | last = self.cursor; | |
396 | let text: SmolStr = match self.cursor.token_tree() { | 397 | let text: SmolStr = match self.cursor.token_tree() { |
397 | Some(tt::TokenTree::Leaf(leaf)) => { | 398 | Some(tt::TokenTree::Leaf(leaf)) => { |
398 | // Mark the range if needed | 399 | // Mark the range if needed |
@@ -441,11 +442,11 @@ impl<'a> TreeSink for TtTreeSink<'a> { | |||
441 | self.inner.token(kind, text); | 442 | self.inner.token(kind, text); |
442 | 443 | ||
443 | // Add whitespace between adjoint puncts | 444 | // Add whitespace between adjoint puncts |
444 | let next = self.cursor.bump(); | 445 | let next = last.bump(); |
445 | if let ( | 446 | if let ( |
446 | Some(tt::TokenTree::Leaf(tt::Leaf::Punct(curr))), | 447 | Some(tt::TokenTree::Leaf(tt::Leaf::Punct(curr))), |
447 | Some(tt::TokenTree::Leaf(tt::Leaf::Punct(_))), | 448 | Some(tt::TokenTree::Leaf(tt::Leaf::Punct(_))), |
448 | ) = (self.cursor.token_tree(), next.token_tree()) | 449 | ) = (last.token_tree(), next.token_tree()) |
449 | { | 450 | { |
450 | if curr.spacing == tt::Spacing::Alone { | 451 | if curr.spacing == tt::Spacing::Alone { |
451 | self.inner.token(WHITESPACE, " ".into()); | 452 | self.inner.token(WHITESPACE, " ".into()); |
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs index 5e6a090aa..304867881 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs | |||
@@ -839,6 +839,37 @@ fn test_tt_composite() { | |||
839 | } | 839 | } |
840 | 840 | ||
841 | #[test] | 841 | #[test] |
842 | fn test_tt_composite2() { | ||
843 | let node = parse_macro( | ||
844 | r#" | ||
845 | macro_rules! foo { | ||
846 | ($($tt:tt)*) => { abs!(=> $($tt)*) } | ||
847 | } | ||
848 | "#, | ||
849 | ) | ||
850 | .expand_items(r#"foo!{#}"#); | ||
851 | |||
852 | let res = format!("{:#?}", &node); | ||
853 | assert_eq_text!( | ||
854 | res.trim(), | ||
855 | r###"MACRO_ITEMS@[0; 10) | ||
856 | MACRO_CALL@[0; 10) | ||
857 | PATH@[0; 3) | ||
858 | PATH_SEGMENT@[0; 3) | ||
859 | NAME_REF@[0; 3) | ||
860 | IDENT@[0; 3) "abs" | ||
861 | EXCL@[3; 4) "!" | ||
862 | TOKEN_TREE@[4; 10) | ||
863 | L_PAREN@[4; 5) "(" | ||
864 | EQ@[5; 6) "=" | ||
865 | R_ANGLE@[6; 7) ">" | ||
866 | WHITESPACE@[7; 8) " " | ||
867 | POUND@[8; 9) "#" | ||
868 | R_PAREN@[9; 10) ")""### | ||
869 | ); | ||
870 | } | ||
871 | |||
872 | #[test] | ||
842 | fn test_lifetime() { | 873 | fn test_lifetime() { |
843 | parse_macro( | 874 | parse_macro( |
844 | r#" | 875 | r#" |