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> {
388388 return ;
389389 }
390390
391+ let mut last = self . cursor ;
391392 for _ in 0 ..n_tokens {
392393 if self . cursor . eof ( ) {
393394 break ;
394395 }
395-
396+ last = self . cursor ;
396397 let text: SmolStr = match self . cursor . token_tree ( ) {
397398 Some ( tt:: TokenTree :: Leaf ( leaf) ) => {
398399 // Mark the range if needed
@@ -441,11 +442,11 @@ impl<'a> TreeSink for TtTreeSink<'a> {
441442 self . inner . token ( kind, text) ;
442443
443444 // Add whitespace between adjoint puncts
444- let next = self . cursor . bump ( ) ;
445+ let next = last . bump ( ) ;
445446 if let (
446447 Some ( tt:: TokenTree :: Leaf ( tt:: Leaf :: Punct ( curr) ) ) ,
447448 Some ( tt:: TokenTree :: Leaf ( tt:: Leaf :: Punct ( _) ) ) ,
448- ) = ( self . cursor . token_tree ( ) , next. token_tree ( ) )
449+ ) = ( last . token_tree ( ) , next. token_tree ( ) )
449450 {
450451 if curr. spacing == tt:: Spacing :: Alone {
451452 self . inner . token ( WHITESPACE , " " . into ( ) ) ;
Original file line number Diff line number Diff line change @@ -838,6 +838,37 @@ fn test_tt_composite() {
838838 . assert_expand_items ( r#"foo! { => }"# , r#"0"# ) ;
839839}
840840
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+
841872#[ test]
842873fn test_lifetime ( ) {
843874 parse_macro (
You can’t perform that action at this time.
0 commit comments