forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#79978 - Aaron1011:fix/capture-broken-token, r…
…=petrochenkov Properly capture trailing 'unglued' token If we try to capture the `Vec<u8>` in `Option<Vec<u8>>`, we'll need to capture a `>` token which was 'unglued' from a `>>` token. The processing of unglueing a token for parsing purposes bypasses the usual capturing infrastructure, so we currently lose the trailing `>`. As a result, we fall back to the reparsed `TokenStream`, causing us to lose spans. This commit makes token capturing keep track of a trailing 'unglued' token. Note that we don't need to care about unglueing except at the end of the captured tokens - if we capture both the first and second unglued tokens, then we'll end up capturing the full 'glued' token, which already works correctly.
- Loading branch information
Showing
3 changed files
with
106 additions
and
9 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,20 @@ | ||
// aux-build:test-macros.rs | ||
// compile-flags: -Z span-debug | ||
// check-pass | ||
|
||
// Tests that we properly handle parsing a nonterminal | ||
// where we have two consecutive angle brackets (one inside | ||
// the nonterminal, and one outside) | ||
|
||
#![no_std] // Don't load unnecessary hygiene information from std | ||
extern crate std; | ||
extern crate test_macros; | ||
|
||
macro_rules! trailing_angle { | ||
(Option<$field:ty>) => { | ||
test_macros::print_bang_consume!($field); | ||
} | ||
} | ||
|
||
trailing_angle!(Option<Vec<u8>>); | ||
fn main() {} |
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,28 @@ | ||
PRINT-BANG INPUT (DISPLAY): Vec<u8> | ||
PRINT-BANG RE-COLLECTED (DISPLAY): Vec < u8 > | ||
PRINT-BANG INPUT (DEBUG): TokenStream [ | ||
Group { | ||
delimiter: None, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "Vec", | ||
span: $DIR/capture-unglued-token.rs:19:24: 19:27 (#0), | ||
}, | ||
Punct { | ||
ch: '<', | ||
spacing: Alone, | ||
span: $DIR/capture-unglued-token.rs:19:27: 19:28 (#0), | ||
}, | ||
Ident { | ||
ident: "u8", | ||
span: $DIR/capture-unglued-token.rs:19:28: 19:30 (#0), | ||
}, | ||
Punct { | ||
ch: '>', | ||
spacing: Alone, | ||
span: $DIR/capture-unglued-token.rs:19:30: 19:31 (#0), | ||
}, | ||
], | ||
span: $DIR/capture-unglued-token.rs:15:42: 15:48 (#4), | ||
}, | ||
] |