@@ -450,48 +450,50 @@ impl<'a> Parser<'a> {
450
450
451
451
let mut expected = edible
452
452
.iter()
453
- .map(|x| TokenType::Token(x.clone()))
454
- .chain(inedible.iter().map(|x| TokenType::Token(x.clone())))
453
+ .chain(inedible)
454
+ .cloned()
455
+ .map(TokenType::Token)
455
456
.chain(self.expected_tokens.iter().cloned())
456
- .filter_map (|token| {
457
- // filter out suggestions which suggest the same token which was found and deemed incorrect
457
+ .filter (|token| {
458
+ // Filter out suggestions that suggest the same token which was found and deemed incorrect.
458
459
fn is_ident_eq_keyword(found: &TokenKind, expected: &TokenType) -> bool {
459
- if let TokenKind::Ident(current_sym, _) = found {
460
- if let TokenType::Keyword(suggested_sym) = expected {
461
- return current_sym == suggested_sym;
462
- }
460
+ if let TokenKind::Ident(current_sym, _) = found
461
+ && let TokenType::Keyword(suggested_sym) = expected
462
+ {
463
+ return current_sym == suggested_sym;
463
464
}
464
465
false
465
466
}
466
- if token != parser::TokenType::Token(self.token.kind.clone()) {
467
+
468
+ if *token != parser::TokenType::Token(self.token.kind.clone()) {
467
469
let eq = is_ident_eq_keyword(&self.token.kind, &token);
468
- // if the suggestion is a keyword and the found token is an ident,
470
+ // If the suggestion is a keyword and the found token is an ident,
469
471
// the content of which are equal to the suggestion's content,
470
- // we can remove that suggestion (see the return None statement below)
472
+ // we can remove that suggestion (see the ` return false` below).
471
473
472
- // if this isn't the case however, and the suggestion is a token the
473
- // content of which is the same as the found token's, we remove it as well
474
+ // If this isn't the case however, and the suggestion is a token the
475
+ // content of which is the same as the found token's, we remove it as well.
474
476
if !eq {
475
477
if let TokenType::Token(kind) = &token {
476
478
if kind == &self.token.kind {
477
- return None ;
479
+ return false ;
478
480
}
479
481
}
480
- return Some(token) ;
482
+ return true ;
481
483
}
482
484
}
483
- return None;
485
+ false
484
486
})
485
487
.collect::<Vec<_>>();
486
488
expected.sort_by_cached_key(|x| x.to_string());
487
489
expected.dedup();
488
490
489
491
let sm = self.sess.source_map();
490
492
491
- // Special-case "expected `;`" errors
493
+ // Special-case "expected `;`" errors.
492
494
if expected.contains(&TokenType::Token(token::Semi)) {
493
495
// If the user is trying to write a ternary expression, recover it and
494
- // return an Err to prevent a cascade of irrelevant diagnostics
496
+ // return an Err to prevent a cascade of irrelevant diagnostics.
495
497
if self.prev_token == token::Question
496
498
&& let Err(e) = self.maybe_recover_from_ternary_operator()
497
499
{
0 commit comments