Skip to content

Commit 1456e36

Browse files
committed
Rename Parser::expected_tokens as Parser::expected_token_types.
Because the `Token` type is similar to but different to the `TokenType` type, and the difference is important, so we want to avoid confusion.
1 parent 37e7459 commit 1456e36

File tree

7 files changed

+26
-25
lines changed

7 files changed

+26
-25
lines changed

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn parse_args<'a>(ecx: &ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a,
9595
while p.token != token::Eof {
9696
if !p.eat(&token::Comma) {
9797
if first {
98-
p.clear_expected_tokens();
98+
p.clear_expected_token_types();
9999
}
100100

101101
match p.expect(&token::Comma) {

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,10 @@ impl<'a> Parser<'a> {
483483
})
484484
}
485485

486-
self.expected_tokens.extend(edible.iter().chain(inedible).cloned().map(TokenType::Token));
486+
self.expected_token_types
487+
.extend(edible.iter().chain(inedible).cloned().map(TokenType::Token));
487488
let mut expected = self
488-
.expected_tokens
489+
.expected_token_types
489490
.iter()
490491
.filter(|token| {
491492
// Filter out suggestions that suggest the same token which was found and deemed incorrect.
@@ -785,17 +786,17 @@ impl<'a> Parser<'a> {
785786
let Some((curr_ident, _)) = self.token.ident() else {
786787
return;
787788
};
788-
let expected_tokens: &[TokenType] =
789+
let expected_token_types: &[TokenType] =
789790
expected.len().checked_sub(10).map_or(&expected, |index| &expected[index..]);
790-
let expected_keywords: Vec<Symbol> = expected_tokens
791+
let expected_keywords: Vec<Symbol> = expected_token_types
791792
.iter()
792793
.filter_map(|token| if let TokenType::Keyword(kw) = token { Some(*kw) } else { None })
793794
.collect();
794795

795-
// When there are a few keywords in the last ten elements of `self.expected_tokens` and the current
796-
// token is an identifier, it's probably a misspelled keyword.
797-
// This handles code like `async Move {}`, misspelled `if` in match guard, misspelled `else` in `if`-`else`
798-
// and mispelled `where` in a where clause.
796+
// When there are a few keywords in the last ten elements of `self.expected_token_types`
797+
// and the current token is an identifier, it's probably a misspelled keyword. This handles
798+
// code like `async Move {}`, misspelled `if` in match guard, misspelled `else` in
799+
// `if`-`else` and mispelled `where` in a where clause.
799800
if !expected_keywords.is_empty()
800801
&& !curr_ident.is_used_keyword()
801802
&& let Some(misspelled_kw) = find_similar_kw(curr_ident, &expected_keywords)
@@ -3016,7 +3017,7 @@ impl<'a> Parser<'a> {
30163017
/// Check for exclusive ranges written as `..<`
30173018
pub(crate) fn maybe_err_dotdotlt_syntax(&self, maybe_lt: Token, mut err: Diag<'a>) -> Diag<'a> {
30183019
if maybe_lt == token::Lt
3019-
&& (self.expected_tokens.contains(&TokenType::Token(token::Gt))
3020+
&& (self.expected_token_types.contains(&TokenType::Token(token::Gt))
30203021
|| matches!(self.token.kind, token::Literal(..)))
30213022
{
30223023
err.span_suggestion(

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<'a> Parser<'a> {
152152
return Ok((lhs, parsed_something));
153153
}
154154

155-
self.expected_tokens.push(TokenType::Operator);
155+
self.expected_token_types.push(TokenType::Operator);
156156
while let Some(op) = self.check_assoc_op() {
157157
let lhs_span = self.interpolated_or_expr_span(&lhs);
158158
let cur_op_span = self.token.span;

compiler/rustc_parse/src/parser/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,7 @@ impl<'a> Parser<'a> {
26302630

26312631
if !self.eat_keyword_case(kw::Fn, case) {
26322632
// It is possible for `expect_one_of` to recover given the contents of
2633-
// `self.expected_tokens`, therefore, do not use `self.unexpected()` which doesn't
2633+
// `self.expected_token_types`, therefore, do not use `self.unexpected()` which doesn't
26342634
// account for this.
26352635
match self.expect_one_of(&[], &[]) {
26362636
Ok(Recovered::Yes(_)) => {}

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub struct Parser<'a> {
143143
pub prev_token: Token,
144144
pub capture_cfg: bool,
145145
restrictions: Restrictions,
146-
expected_tokens: Vec<TokenType>,
146+
expected_token_types: Vec<TokenType>,
147147
token_cursor: TokenCursor,
148148
// The number of calls to `bump`, i.e. the position in the token stream.
149149
num_bump_calls: u32,
@@ -464,7 +464,7 @@ impl<'a> Parser<'a> {
464464
prev_token: Token::dummy(),
465465
capture_cfg: false,
466466
restrictions: Restrictions::empty(),
467-
expected_tokens: Vec::new(),
467+
expected_token_types: Vec::new(),
468468
token_cursor: TokenCursor { tree_cursor: stream.into_trees(), stack: Vec::new() },
469469
num_bump_calls: 0,
470470
break_last_token: 0,
@@ -528,7 +528,7 @@ impl<'a> Parser<'a> {
528528

529529
/// Expects and consumes the token `t`. Signals an error if the next token is not `t`.
530530
pub fn expect(&mut self, t: &TokenKind) -> PResult<'a, Recovered> {
531-
if self.expected_tokens.is_empty() {
531+
if self.expected_token_types.is_empty() {
532532
if self.token == *t {
533533
self.bump();
534534
Ok(Recovered::No)
@@ -593,13 +593,13 @@ impl<'a> Parser<'a> {
593593

594594
/// Checks if the next token is `tok`, and returns `true` if so.
595595
///
596-
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
596+
/// This method will automatically add `tok` to `expected_token_types` if `tok` is not
597597
/// encountered.
598598
#[inline]
599599
fn check(&mut self, tok: &TokenKind) -> bool {
600600
let is_present = self.token == *tok;
601601
if !is_present {
602-
self.expected_tokens.push(TokenType::Token(tok.clone()));
602+
self.expected_token_types.push(TokenType::Token(tok.clone()));
603603
}
604604
is_present
605605
}
@@ -640,7 +640,7 @@ impl<'a> Parser<'a> {
640640
#[inline]
641641
#[must_use]
642642
fn check_keyword(&mut self, kw: Symbol) -> bool {
643-
self.expected_tokens.push(TokenType::Keyword(kw));
643+
self.expected_token_types.push(TokenType::Keyword(kw));
644644
self.token.is_keyword(kw)
645645
}
646646

@@ -729,7 +729,7 @@ impl<'a> Parser<'a> {
729729
if ok {
730730
true
731731
} else {
732-
self.expected_tokens.push(typ);
732+
self.expected_token_types.push(typ);
733733
false
734734
}
735735
}
@@ -806,7 +806,7 @@ impl<'a> Parser<'a> {
806806
true
807807
}
808808
_ => {
809-
self.expected_tokens.push(TokenType::Token(expected));
809+
self.expected_token_types.push(TokenType::Token(expected));
810810
false
811811
}
812812
}
@@ -1154,7 +1154,7 @@ impl<'a> Parser<'a> {
11541154
self.token_spacing = next_spacing;
11551155

11561156
// Diagnostics.
1157-
self.expected_tokens.clear();
1157+
self.expected_token_types.clear();
11581158
}
11591159

11601160
/// Advance the parser by one token.
@@ -1642,8 +1642,8 @@ impl<'a> Parser<'a> {
16421642
DebugParser { parser: self, lookahead }
16431643
}
16441644

1645-
pub fn clear_expected_tokens(&mut self) {
1646-
self.expected_tokens.clear();
1645+
pub fn clear_expected_token_types(&mut self) {
1646+
self.expected_token_types.clear();
16471647
}
16481648

16491649
pub fn approx_token_stream_pos(&self) -> u32 {

compiler/rustc_parse/src/parser/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'a> Parser<'a> {
300300
)
301301
};
302302
let check_args_start = |this: &mut Self| {
303-
this.expected_tokens.extend_from_slice(&[
303+
this.expected_token_types.extend_from_slice(&[
304304
TokenType::Token(token::Lt),
305305
TokenType::Token(token::OpenDelim(Delimiter::Parenthesis)),
306306
]);

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ impl<'a> Parser<'a> {
12801280
}
12811281

12821282
pub(super) fn check_lifetime(&mut self) -> bool {
1283-
self.expected_tokens.push(TokenType::Lifetime);
1283+
self.expected_token_types.push(TokenType::Lifetime);
12841284
self.token.is_lifetime()
12851285
}
12861286

0 commit comments

Comments
 (0)