-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix recursive nonterminal expansion during pretty-print/reparse check
Makes progress towards #43081 In PR #73084, we started recursively expanded nonterminals during the pretty-print/reparse check, allowing them to be properly compared against the reparsed tokenstream. Unfortunately, the recursive logic in that PR only handles the case where a nonterminal appears inside a `TokenTree::Delimited`. If a nonterminal appears directly in the expanded tokens of another nonterminal, the inner nonterminal will not be expanded. This PR fixes the recursive expansion of nonterminals, ensuring that they are expanded wherever they occur.
- Loading branch information
Showing
3 changed files
with
120 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// check-pass | ||
// edition:2018 | ||
// compile-flags: -Z span-debug | ||
// aux-build:test-macros.rs | ||
|
||
// Tests that we properly pass tokens to proc-macro when nested | ||
// nonterminals are involved. | ||
|
||
#![no_std] // Don't load unnecessary hygiene information from std | ||
extern crate std; | ||
|
||
#[macro_use] | ||
extern crate test_macros; | ||
|
||
|
||
macro_rules! wrap { | ||
(first, $e:expr) => { wrap!(second, $e + 1) }; | ||
(second, $e:expr) => { wrap!(third, $e + 2) }; | ||
(third, $e:expr) => { | ||
print_bang!($e + 3); | ||
}; | ||
} | ||
|
||
fn main() { | ||
let _ = wrap!(first, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
PRINT-BANG INPUT (DISPLAY): 0 + 1 + 2 + 3 | ||
PRINT-BANG INPUT (DEBUG): TokenStream [ | ||
Group { | ||
delimiter: None, | ||
stream: TokenStream [ | ||
Group { | ||
delimiter: None, | ||
stream: TokenStream [ | ||
Group { | ||
delimiter: None, | ||
stream: TokenStream [ | ||
Literal { | ||
kind: Integer, | ||
symbol: "0", | ||
suffix: None, | ||
span: $DIR/nested-nonterminal-tokens.rs:25:26: 25:27 (#0), | ||
}, | ||
], | ||
span: $DIR/nested-nonterminal-tokens.rs:17:41: 17:43 (#4), | ||
}, | ||
Punct { | ||
ch: '+', | ||
spacing: Alone, | ||
span: $DIR/nested-nonterminal-tokens.rs:17:44: 17:45 (#4), | ||
}, | ||
Literal { | ||
kind: Integer, | ||
symbol: "1", | ||
suffix: None, | ||
span: $DIR/nested-nonterminal-tokens.rs:17:46: 17:47 (#4), | ||
}, | ||
], | ||
span: $DIR/nested-nonterminal-tokens.rs:18:41: 18:43 (#5), | ||
}, | ||
Punct { | ||
ch: '+', | ||
spacing: Alone, | ||
span: $DIR/nested-nonterminal-tokens.rs:18:44: 18:45 (#5), | ||
}, | ||
Literal { | ||
kind: Integer, | ||
symbol: "2", | ||
suffix: None, | ||
span: $DIR/nested-nonterminal-tokens.rs:18:46: 18:47 (#5), | ||
}, | ||
], | ||
span: $DIR/nested-nonterminal-tokens.rs:20:21: 20:23 (#6), | ||
}, | ||
Punct { | ||
ch: '+', | ||
spacing: Alone, | ||
span: $DIR/nested-nonterminal-tokens.rs:20:24: 20:25 (#6), | ||
}, | ||
Literal { | ||
kind: Integer, | ||
symbol: "3", | ||
suffix: None, | ||
span: $DIR/nested-nonterminal-tokens.rs:20:26: 20:27 (#6), | ||
}, | ||
] |