diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-13 15:53:31 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-13 16:42:00 +1000 |
| commit | aa0e8e147588c75fbb6ad158140c890582886027 (patch) | |
| tree | 5ec3bc108f0c720a3f5e14110799a176ae96a9f6 /compiler/rustc_parse/src/parser/tests.rs | |
| parent | cf2dfb2ced7862077ceff468c679f44d1e6d56cc (diff) | |
| download | rust-aa0e8e147588c75fbb6ad158140c890582886027.tar.gz rust-aa0e8e147588c75fbb6ad158140c890582886027.zip | |
Fix `DebugParser`.
It currently doesn't work at all. This commit changes it to a simpler imperative style that produces a valid `tokens` vec. (An aside: I find `Iterator::scan` to be a pretty wretched function, that produces code which is very hard to understand. Probably why this is just one of two uses of it in the entire compiler.)
Diffstat (limited to 'compiler/rustc_parse/src/parser/tests.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/tests.rs | 100 |
1 files changed, 94 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/tests.rs b/compiler/rustc_parse/src/parser/tests.rs index 8703d5b8490..cf791d332a2 100644 --- a/compiler/rustc_parse/src/parser/tests.rs +++ b/compiler/rustc_parse/src/parser/tests.rs @@ -1541,11 +1541,36 @@ fn debug_lookahead() { ctxt: #0, }, }, - tokens: [], + tokens: [ + Ident( + \"fn\", + No, + ), + Ident( + \"f\", + No, + ), + OpenDelim( + Parenthesis, + ), + Ident( + \"x\", + No, + ), + Colon, + Ident( + \"u32\", + No, + ), + CloseDelim( + Parenthesis, + ), + ], approx_token_stream_pos: 1, .. }" ); + // There are 13 tokens. We request 15, get 14; the last one is `Eof`. assert_eq!( &format!("{:#?}", p.debug_lookahead(15)), "Parser { @@ -1561,7 +1586,51 @@ fn debug_lookahead() { ctxt: #0, }, }, - tokens: [], + tokens: [ + Ident( + \"fn\", + No, + ), + Ident( + \"f\", + No, + ), + OpenDelim( + Parenthesis, + ), + Ident( + \"x\", + No, + ), + Colon, + Ident( + \"u32\", + No, + ), + CloseDelim( + Parenthesis, + ), + OpenDelim( + Brace, + ), + Ident( + \"x\", + No, + ), + CloseDelim( + Brace, + ), + Ident( + \"struct\", + No, + ), + Ident( + \"S\", + No, + ), + Semi, + Eof, + ], approx_token_stream_pos: 1, .. }" @@ -1588,7 +1657,12 @@ fn debug_lookahead() { ctxt: #0, }, }, - tokens: [], + tokens: [ + Ident( + \"x\", + No, + ), + ], approx_token_stream_pos: 9, .. }" @@ -1610,7 +1684,23 @@ fn debug_lookahead() { ctxt: #0, }, }, - tokens: [], + tokens: [ + Ident( + \"x\", + No, + ), + CloseDelim( + Brace, + ), + Ident( + \"struct\", + No, + ), + Ident( + \"S\", + No, + ), + ], approx_token_stream_pos: 9, .. }" @@ -1637,8 +1727,6 @@ fn debug_lookahead() { }, tokens: [ Eof, - Eof, - Eof, ], approx_token_stream_pos: 15, .. |
