@@ -450,48 +450,50 @@ impl<'a> Parser<'a> {
450450
451451 let mut expected = edible
452452 . 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 )
455456 . 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.
458459 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 ;
463464 }
464465 false
465466 }
466- if token != parser:: TokenType :: Token ( self . token . kind . clone ( ) ) {
467+
468+ if * token != parser:: TokenType :: Token ( self . token . kind . clone ( ) ) {
467469 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,
469471 // 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).
471473
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.
474476 if !eq {
475477 if let TokenType :: Token ( kind) = & token {
476478 if kind == & self . token . kind {
477- return None ;
479+ return false ;
478480 }
479481 }
480- return Some ( token ) ;
482+ return true ;
481483 }
482484 }
483- return None ;
485+ false
484486 } )
485487 . collect :: < Vec < _ > > ( ) ;
486488 expected. sort_by_cached_key ( |x| x. to_string ( ) ) ;
487489 expected. dedup ( ) ;
488490
489491 let sm = self . sess . source_map ( ) ;
490492
491- // Special-case "expected `;`" errors
493+ // Special-case "expected `;`" errors.
492494 if expected. contains ( & TokenType :: Token ( token:: Semi ) ) {
493495 // 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.
495497 if self . prev_token == token:: Question
496498 && let Err ( e) = self . maybe_recover_from_ternary_operator ( )
497499 {
0 commit comments