Skip to content

Commit 93403de

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 e93e096 commit 93403de

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
@@ -96,7 +96,7 @@ fn parse_args<'a>(ecx: &ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a,
9696
while p.token != token::Eof {
9797
if !p.eat(&token::Comma) {
9898
if first {
99-
p.clear_expected_tokens();
99+
p.clear_expected_token_types();
100100
}
101101

102102
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: PErr<'a>) -> PErr<'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
@@ -2610,7 +2610,7 @@ impl<'a> Parser<'a> {
26102610

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

compiler/rustc_parse/src/parser/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub struct Parser<'a> {
144144
pub prev_token: Token,
145145
pub capture_cfg: bool,
146146
restrictions: Restrictions,
147-
expected_tokens: Vec<TokenType>,
147+
expected_token_types: Vec<TokenType>,
148148
token_cursor: TokenCursor,
149149
// The number of calls to `bump`, i.e. the position in the token stream.
150150
num_bump_calls: u32,
@@ -465,7 +465,7 @@ impl<'a> Parser<'a> {
465465
prev_token: Token::dummy(),
466466
capture_cfg: false,
467467
restrictions: Restrictions::empty(),
468-
expected_tokens: Vec::new(),
468+
expected_token_types: Vec::new(),
469469
token_cursor: TokenCursor { tree_cursor: stream.into_trees(), stack: Vec::new() },
470470
num_bump_calls: 0,
471471
break_last_token: 0,
@@ -529,7 +529,7 @@ impl<'a> Parser<'a> {
529529

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

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

@@ -730,7 +730,7 @@ impl<'a> Parser<'a> {
730730
if ok {
731731
true
732732
} else {
733-
self.expected_tokens.push(typ);
733+
self.expected_token_types.push(typ);
734734
false
735735
}
736736
}
@@ -807,7 +807,7 @@ impl<'a> Parser<'a> {
807807
true
808808
}
809809
_ => {
810-
self.expected_tokens.push(TokenType::Token(expected));
810+
self.expected_token_types.push(TokenType::Token(expected));
811811
false
812812
}
813813
}
@@ -1155,7 +1155,7 @@ impl<'a> Parser<'a> {
11551155
self.token_spacing = next_spacing;
11561156

11571157
// Diagnostics.
1158-
self.expected_tokens.clear();
1158+
self.expected_token_types.clear();
11591159
}
11601160

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

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

16501650
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
@@ -301,7 +301,7 @@ impl<'a> Parser<'a> {
301301
)
302302
};
303303
let check_args_start = |this: &mut Self| {
304-
this.expected_tokens.extend_from_slice(&[
304+
this.expected_token_types.extend_from_slice(&[
305305
TokenType::Token(token::Lt),
306306
TokenType::Token(token::OpenDelim(Delimiter::Parenthesis)),
307307
]);

compiler/rustc_parse/src/parser/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ impl<'a> Parser<'a> {
12641264
}
12651265

12661266
pub(super) fn check_lifetime(&mut self) -> bool {
1267-
self.expected_tokens.push(TokenType::Lifetime);
1267+
self.expected_token_types.push(TokenType::Lifetime);
12681268
self.token.is_lifetime()
12691269
}
12701270

0 commit comments

Comments
 (0)