Skip to content

Commit 48f7714

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 c434b4b commit 48f7714

File tree

7 files changed

+26
-25
lines changed

7 files changed

+26
-25
lines changed

compiler/rustc_builtin_macros/src/format.rs

+1-1
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

+10-9
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'a> Parser<'a> {
153153
return Ok((lhs, parsed_something));
154154
}
155155

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

compiler/rustc_parse/src/parser/item.rs

+1-1
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

+11-11
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub struct Parser<'a> {
141141
pub prev_token: Token,
142142
pub capture_cfg: bool,
143143
restrictions: Restrictions,
144-
expected_tokens: Vec<TokenType>,
144+
expected_token_types: Vec<TokenType>,
145145
token_cursor: TokenCursor,
146146
// The number of calls to `bump`, i.e. the position in the token stream.
147147
num_bump_calls: u32,
@@ -490,7 +490,7 @@ impl<'a> Parser<'a> {
490490
prev_token: Token::dummy(),
491491
capture_cfg: false,
492492
restrictions: Restrictions::empty(),
493-
expected_tokens: Vec::new(),
493+
expected_token_types: Vec::new(),
494494
token_cursor: TokenCursor { curr: TokenTreeCursor::new(stream), stack: Vec::new() },
495495
num_bump_calls: 0,
496496
break_last_token: 0,
@@ -554,7 +554,7 @@ impl<'a> Parser<'a> {
554554

555555
/// Expects and consumes the token `t`. Signals an error if the next token is not `t`.
556556
pub fn expect(&mut self, t: &TokenKind) -> PResult<'a, Recovered> {
557-
if self.expected_tokens.is_empty() {
557+
if self.expected_token_types.is_empty() {
558558
if self.token == *t {
559559
self.bump();
560560
Ok(Recovered::No)
@@ -619,13 +619,13 @@ impl<'a> Parser<'a> {
619619

620620
/// Checks if the next token is `tok`, and returns `true` if so.
621621
///
622-
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
622+
/// This method will automatically add `tok` to `expected_token_types` if `tok` is not
623623
/// encountered.
624624
#[inline]
625625
fn check(&mut self, tok: &TokenKind) -> bool {
626626
let is_present = self.token == *tok;
627627
if !is_present {
628-
self.expected_tokens.push(TokenType::Token(tok.clone()));
628+
self.expected_token_types.push(TokenType::Token(tok.clone()));
629629
}
630630
is_present
631631
}
@@ -666,7 +666,7 @@ impl<'a> Parser<'a> {
666666
#[inline]
667667
#[must_use]
668668
fn check_keyword(&mut self, kw: Symbol) -> bool {
669-
self.expected_tokens.push(TokenType::Keyword(kw));
669+
self.expected_token_types.push(TokenType::Keyword(kw));
670670
self.token.is_keyword(kw)
671671
}
672672

@@ -755,7 +755,7 @@ impl<'a> Parser<'a> {
755755
if ok {
756756
true
757757
} else {
758-
self.expected_tokens.push(typ);
758+
self.expected_token_types.push(typ);
759759
false
760760
}
761761
}
@@ -832,7 +832,7 @@ impl<'a> Parser<'a> {
832832
true
833833
}
834834
_ => {
835-
self.expected_tokens.push(TokenType::Token(expected));
835+
self.expected_token_types.push(TokenType::Token(expected));
836836
false
837837
}
838838
}
@@ -1180,7 +1180,7 @@ impl<'a> Parser<'a> {
11801180
self.token_spacing = next_spacing;
11811181

11821182
// Diagnostics.
1183-
self.expected_tokens.clear();
1183+
self.expected_token_types.clear();
11841184
}
11851185

11861186
/// Advance the parser by one token.
@@ -1670,8 +1670,8 @@ impl<'a> Parser<'a> {
16701670
DebugParser { parser: self, lookahead }
16711671
}
16721672

1673-
pub fn clear_expected_tokens(&mut self) {
1674-
self.expected_tokens.clear();
1673+
pub fn clear_expected_token_types(&mut self) {
1674+
self.expected_token_types.clear();
16751675
}
16761676

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

compiler/rustc_parse/src/parser/path.rs

+1-1
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

+1-1
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)