@@ -620,6 +620,55 @@ impl<'a> Parser<'a> {
620620 ) ;
621621 }
622622
623+ // Possible missing `struct` or `enum` keyword
624+ if let TokenKind :: Ident ( symbol, _) = & self . prev_token . kind
625+ && let TokenKind :: OpenDelim ( Delimiter :: Brace ) = self . token . kind
626+ && let [ TokenType :: Token ( token:: Not ) , TokenType :: Token ( token:: PathSep ) ] = expected[ ..]
627+ {
628+ let mut lookahead = self . clone ( ) ;
629+ for position in 1 ..1000 {
630+ lookahead. bump ( ) ;
631+ if lookahead. token == token:: CloseDelim ( Delimiter :: Brace )
632+ || lookahead. token == token:: Colon
633+ {
634+ let ( article, kw) = if lookahead. token == token:: Colon || position == 1 {
635+ ( "a" , "struct" )
636+ } else {
637+ ( "an" , "enum" )
638+ } ;
639+ err. span_suggestion (
640+ self . prev_token . span ,
641+ format ! ( "if this is {article} {kw} definition, use the `{kw}` keyword" ) ,
642+ format ! ( "{kw} {symbol}" ) ,
643+ Applicability :: MaybeIncorrect ,
644+ ) ;
645+ break ;
646+ }
647+ }
648+ }
649+
650+ // Possible missing `fn` keyword
651+ if let TokenKind :: Ident ( symbol, _) = & self . prev_token . kind
652+ && let TokenKind :: OpenDelim ( Delimiter :: Parenthesis ) = self . token . kind
653+ {
654+ let mut lookahead = self . clone ( ) ;
655+ for _ in 1 ..100 {
656+ lookahead. bump ( ) ;
657+ if lookahead. token == token:: Semi {
658+ break ;
659+ }
660+ if lookahead. token == token:: OpenDelim ( Delimiter :: Brace ) {
661+ err. span_suggestion (
662+ self . prev_token . span ,
663+ "if this is a function definition, use the `fn` keyword" ,
664+ format ! ( "fn {symbol}" ) ,
665+ Applicability :: MaybeIncorrect ,
666+ ) ;
667+ break ;
668+ }
669+ }
670+ }
671+
623672 if let TokenKind :: Ident ( symbol, _) = & self . prev_token . kind {
624673 if [ "def" , "fun" , "func" , "function" ] . contains ( & symbol. as_str ( ) ) {
625674 err. span_suggestion_short (
0 commit comments