File tree Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ fn expand_subtree(
9797 err = err. or ( e) ;
9898 arena. push ( tt. into ( ) ) ;
9999 }
100- Op :: Var { name, kind : _ } => {
100+ Op :: Var { name, .. } => {
101101 let ExpandResult { value : fragment, err : e } = expand_var ( ctx, name) ;
102102 err = err. or ( e) ;
103103 push_fragment ( arena, fragment) ;
Original file line number Diff line number Diff line change @@ -101,7 +101,9 @@ fn next_op<'a>(
101101 Op :: Repeat { subtree, separator, kind }
102102 }
103103 tt:: TokenTree :: Leaf ( leaf) => match leaf {
104- tt:: Leaf :: Punct ( ..) => return Err ( ExpandError :: UnexpectedToken ) ,
104+ tt:: Leaf :: Punct ( _) => {
105+ return Err ( ExpandError :: UnexpectedToken ) ;
106+ }
105107 tt:: Leaf :: Ident ( ident) => {
106108 let name = & ident. text ;
107109 let kind = eat_fragment_kind ( src, mode) ?;
Original file line number Diff line number Diff line change @@ -313,7 +313,7 @@ trait TokenConvertor {
313313 return ;
314314 }
315315
316- result. push ( if k. is_punct ( ) {
316+ result. push ( if k. is_punct ( ) && k != UNDERSCORE {
317317 assert_eq ! ( range. len( ) , TextSize :: of( '.' ) ) ;
318318 let delim = match k {
319319 T ! [ '(' ] => Some ( ( tt:: DelimiterKind :: Parenthesis , T ! [ ')' ] ) ) ,
@@ -378,6 +378,7 @@ trait TokenConvertor {
378378 let leaf: tt:: Leaf = match k {
379379 T ! [ true ] | T ! [ false ] => make_leaf ! ( Ident ) ,
380380 IDENT => make_leaf ! ( Ident ) ,
381+ UNDERSCORE => make_leaf ! ( Ident ) ,
381382 k if k. is_keyword ( ) => make_leaf ! ( Ident ) ,
382383 k if k. is_literal ( ) => make_leaf ! ( Literal ) ,
383384 LIFETIME_IDENT => {
Original file line number Diff line number Diff line change @@ -991,6 +991,18 @@ fn test_tt_composite2() {
991991 ) ;
992992}
993993
994+ #[ test]
995+ fn test_underscore ( ) {
996+ parse_macro (
997+ r#"
998+ macro_rules! foo {
999+ ($_:tt) => { 0 }
1000+ }
1001+ "# ,
1002+ )
1003+ . assert_expand_items ( r#"foo! { => }"# , r#"0"# ) ;
1004+ }
1005+
9941006#[ test]
9951007fn test_lifetime ( ) {
9961008 parse_macro (
You can’t perform that action at this time.
0 commit comments