Skip to content

Commit dbe6819

Browse files
authored
Unrolled build for rust-lang#127273
Rollup merge of rust-lang#127273 - nnethercote:fix-DebugParser, r=workingjubilee Fix `DebugParser`. I tried using this and it didn't work at all. `prev_token` is never eof, so the accumulator is always false, which means the `then_some` always returns `None`, which means `scan` always returns `None`, and `tokens` always ends up an empty vec. I'm not sure how this code was supposed to work. (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.) This commit changes it to a simpler imperative style that produces a valid `tokens` vec. r? `@workingjubilee`
2 parents 0968298 + aa0e8e1 commit dbe6819

File tree

2 files changed

+310
-70
lines changed

2 files changed

+310
-70
lines changed

compiler/rustc_parse/src/parser/mod.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1537,14 +1537,16 @@ impl<'a> Parser<'a> {
15371537

15381538
// we don't need N spans, but we want at least one, so print all of prev_token
15391539
dbg_fmt.field("prev_token", &parser.prev_token);
1540-
// make it easier to peek farther ahead by taking TokenKinds only until EOF
1541-
let tokens = (0..*lookahead)
1542-
.map(|i| parser.look_ahead(i, |tok| tok.kind.clone()))
1543-
.scan(parser.prev_token == TokenKind::Eof, |eof, tok| {
1544-
let current = eof.then_some(tok.clone()); // include a trailing EOF token
1545-
*eof |= &tok == &TokenKind::Eof;
1546-
current
1547-
});
1540+
let mut tokens = vec![];
1541+
for i in 0..*lookahead {
1542+
let tok = parser.look_ahead(i, |tok| tok.kind.clone());
1543+
let is_eof = tok == TokenKind::Eof;
1544+
tokens.push(tok);
1545+
if is_eof {
1546+
// Don't look ahead past EOF.
1547+
break;
1548+
}
1549+
}
15481550
dbg_fmt.field_with("tokens", |field| field.debug_list().entries(tokens).finish());
15491551
dbg_fmt.field("approx_token_stream_pos", &parser.num_bump_calls);
15501552

0 commit comments

Comments
 (0)