Skip to content

Commit ca66495

Browse files
committed
Make Parser::num_bump_calls 0-indexed.
Currently in `collect_tokens_trailing_token`, `start_pos` and `end_pos` are 1-indexed by `replace_ranges` is 0-indexed, which is really confusing. Making them both 0-indexed makes debugging much easier.
1 parent f9c7ca7 commit ca66495

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

compiler/rustc_parse/src/parser/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ impl<'a> Parser<'a> {
425425
// Make parser point to the first token.
426426
parser.bump();
427427

428+
// Change this from 1 back to 0 after the bump. This eases debugging of
429+
// `Parser::collect_tokens_trailing_token` nicer because it makes the
430+
// token positions 0-indexed which is nicer than 1-indexed.
431+
parser.num_bump_calls = 0;
432+
428433
parser
429434
}
430435

compiler/rustc_parse/src/parser/tests.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ fn debug_lookahead() {
15221522
},
15231523
},
15241524
tokens: [],
1525-
approx_token_stream_pos: 1,
1525+
approx_token_stream_pos: 0,
15261526
..
15271527
}"
15281528
);
@@ -1566,7 +1566,7 @@ fn debug_lookahead() {
15661566
Parenthesis,
15671567
),
15681568
],
1569-
approx_token_stream_pos: 1,
1569+
approx_token_stream_pos: 0,
15701570
..
15711571
}"
15721572
);
@@ -1631,7 +1631,7 @@ fn debug_lookahead() {
16311631
Semi,
16321632
Eof,
16331633
],
1634-
approx_token_stream_pos: 1,
1634+
approx_token_stream_pos: 0,
16351635
..
16361636
}"
16371637
);
@@ -1663,7 +1663,7 @@ fn debug_lookahead() {
16631663
No,
16641664
),
16651665
],
1666-
approx_token_stream_pos: 9,
1666+
approx_token_stream_pos: 8,
16671667
..
16681668
}"
16691669
);
@@ -1701,7 +1701,7 @@ fn debug_lookahead() {
17011701
No,
17021702
),
17031703
],
1704-
approx_token_stream_pos: 9,
1704+
approx_token_stream_pos: 8,
17051705
..
17061706
}"
17071707
);
@@ -1728,7 +1728,7 @@ fn debug_lookahead() {
17281728
tokens: [
17291729
Eof,
17301730
],
1731-
approx_token_stream_pos: 15,
1731+
approx_token_stream_pos: 14,
17321732
..
17331733
}"
17341734
);

0 commit comments

Comments
 (0)