File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -388,11 +388,12 @@ impl<'a> TreeSink for TtTreeSink<'a> {
388
388
return ;
389
389
}
390
390
391
+ let mut last = self . cursor ;
391
392
for _ in 0 ..n_tokens {
392
393
if self . cursor . eof ( ) {
393
394
break ;
394
395
}
395
-
396
+ last = self . cursor ;
396
397
let text: SmolStr = match self . cursor . token_tree ( ) {
397
398
Some ( tt:: TokenTree :: Leaf ( leaf) ) => {
398
399
// Mark the range if needed
@@ -441,11 +442,11 @@ impl<'a> TreeSink for TtTreeSink<'a> {
441
442
self . inner . token ( kind, text) ;
442
443
443
444
// Add whitespace between adjoint puncts
444
- let next = self . cursor . bump ( ) ;
445
+ let next = last . bump ( ) ;
445
446
if let (
446
447
Some ( tt:: TokenTree :: Leaf ( tt:: Leaf :: Punct ( curr) ) ) ,
447
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
451
if curr. spacing == tt:: Spacing :: Alone {
451
452
self . inner . token ( WHITESPACE , " " . into ( ) ) ;
Original file line number Diff line number Diff line change @@ -838,6 +838,37 @@ fn test_tt_composite() {
838
838
. assert_expand_items ( r#"foo! { => }"# , r#"0"# ) ;
839
839
}
840
840
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
+
841
872
#[ test]
842
873
fn test_lifetime ( ) {
843
874
parse_macro (
You can’t perform that action at this time.
0 commit comments