@@ -824,90 +824,88 @@ impl<'a> Parser<'a> {
824824
825825 // Note: when adding new syntax here, don't forget to adjust `TokenKind::can_begin_expr()`.
826826 let lo = self . token . span ;
827- match self . token . kind {
827+ if let token :: Literal ( _ ) = self . token . kind {
828828 // This match arm is a special-case of the `_` match arm below and
829829 // could be removed without changing functionality, but it's faster
830830 // to have it here, especially for programs with large constants.
831- token:: Literal ( _) => self . parse_lit_expr ( attrs) ,
832- token:: OpenDelim ( token:: Paren ) => self . parse_tuple_parens_expr ( attrs) ,
833- token:: OpenDelim ( token:: Brace ) => {
834- self . parse_block_expr ( None , lo, BlockCheckMode :: Default , attrs)
835- }
836- token:: BinOp ( token:: Or ) | token:: OrOr => self . parse_closure_expr ( attrs) ,
837- token:: OpenDelim ( token:: Bracket ) => self . parse_array_or_repeat_expr ( attrs) ,
838- _ => {
839- if self . eat_lt ( ) {
840- let ( qself, path) = self . parse_qpath ( PathStyle :: Expr ) ?;
841- Ok ( self . mk_expr ( lo. to ( path. span ) , ExprKind :: Path ( Some ( qself) , path) , attrs) )
842- } else if self . token . is_path_start ( ) {
843- self . parse_path_start_expr ( attrs)
844- } else if self . check_keyword ( kw:: Move ) || self . check_keyword ( kw:: Static ) {
845- self . parse_closure_expr ( attrs)
846- } else if self . eat_keyword ( kw:: If ) {
847- self . parse_if_expr ( attrs)
848- } else if self . eat_keyword ( kw:: For ) {
849- self . parse_for_expr ( None , self . prev_span , attrs)
850- } else if self . eat_keyword ( kw:: While ) {
851- self . parse_while_expr ( None , self . prev_span , attrs)
852- } else if let Some ( label) = self . eat_label ( ) {
853- self . parse_labeled_expr ( label, attrs)
854- } else if self . eat_keyword ( kw:: Loop ) {
855- self . parse_loop_expr ( None , self . prev_span , attrs)
856- } else if self . eat_keyword ( kw:: Continue ) {
857- let kind = ExprKind :: Continue ( self . eat_label ( ) ) ;
858- Ok ( self . mk_expr ( lo. to ( self . prev_span ) , kind, attrs) )
859- } else if self . eat_keyword ( kw:: Match ) {
860- let match_sp = self . prev_span ;
861- self . parse_match_expr ( attrs) . map_err ( |mut err| {
862- err. span_label ( match_sp, "while parsing this match expression" ) ;
863- err
864- } )
865- } else if self . eat_keyword ( kw:: Unsafe ) {
866- let mode = BlockCheckMode :: Unsafe ( ast:: UserProvided ) ;
867- self . parse_block_expr ( None , lo, mode, attrs)
868- } else if self . is_do_catch_block ( ) {
869- self . recover_do_catch ( attrs)
870- } else if self . is_try_block ( ) {
871- self . expect_keyword ( kw:: Try ) ?;
872- self . parse_try_block ( lo, attrs)
873- } else if self . eat_keyword ( kw:: Return ) {
874- self . parse_return_expr ( attrs)
875- } else if self . eat_keyword ( kw:: Break ) {
876- self . parse_break_expr ( attrs)
877- } else if self . eat_keyword ( kw:: Yield ) {
878- self . parse_yield_expr ( attrs)
879- } else if self . eat_keyword ( kw:: Let ) {
880- self . parse_let_expr ( attrs)
881- } else if !self . unclosed_delims . is_empty ( ) && self . check ( & token:: Semi ) {
882- // Don't complain about bare semicolons after unclosed braces
883- // recovery in order to keep the error count down. Fixing the
884- // delimiters will possibly also fix the bare semicolon found in
885- // expression context. For example, silence the following error:
886- //
887- // error: expected expression, found `;`
888- // --> file.rs:2:13
889- // |
890- // 2 | foo(bar(;
891- // | ^ expected expression
892- self . bump ( ) ;
893- Ok ( self . mk_expr_err ( self . token . span ) )
894- } else if self . token . span . rust_2018 ( ) {
895- // `Span::rust_2018()` is somewhat expensive; don't get it repeatedly.
896- if self . check_keyword ( kw:: Async ) {
897- if self . is_async_block ( ) { // Check for `async {` and `async move {`.
898- self . parse_async_block ( attrs)
899- } else {
900- self . parse_closure_expr ( attrs)
901- }
902- } else if self . eat_keyword ( kw:: Await ) {
903- self . recover_incorrect_await_syntax ( lo, self . prev_span , attrs)
904- } else {
905- self . parse_lit_expr ( attrs)
906- }
831+ self . parse_lit_expr ( attrs)
832+ } else if self . check ( & token:: OpenDelim ( token:: Paren ) ) {
833+ self . parse_tuple_parens_expr ( attrs)
834+ } else if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
835+ self . parse_block_expr ( None , lo, BlockCheckMode :: Default , attrs)
836+ } else if self . check ( & token:: BinOp ( token:: Or ) ) || self . check ( & token:: OrOr ) {
837+ self . parse_closure_expr ( attrs)
838+ } else if self . check ( & token:: OpenDelim ( token:: Bracket ) ) {
839+ self . parse_array_or_repeat_expr ( attrs)
840+ } else if self . eat_lt ( ) {
841+ let ( qself, path) = self . parse_qpath ( PathStyle :: Expr ) ?;
842+ Ok ( self . mk_expr ( lo. to ( path. span ) , ExprKind :: Path ( Some ( qself) , path) , attrs) )
843+ } else if self . token . is_path_start ( ) {
844+ self . parse_path_start_expr ( attrs)
845+ } else if self . check_keyword ( kw:: Move ) || self . check_keyword ( kw:: Static ) {
846+ self . parse_closure_expr ( attrs)
847+ } else if self . eat_keyword ( kw:: If ) {
848+ self . parse_if_expr ( attrs)
849+ } else if self . eat_keyword ( kw:: For ) {
850+ self . parse_for_expr ( None , self . prev_span , attrs)
851+ } else if self . eat_keyword ( kw:: While ) {
852+ self . parse_while_expr ( None , self . prev_span , attrs)
853+ } else if let Some ( label) = self . eat_label ( ) {
854+ self . parse_labeled_expr ( label, attrs)
855+ } else if self . eat_keyword ( kw:: Loop ) {
856+ self . parse_loop_expr ( None , self . prev_span , attrs)
857+ } else if self . eat_keyword ( kw:: Continue ) {
858+ let kind = ExprKind :: Continue ( self . eat_label ( ) ) ;
859+ Ok ( self . mk_expr ( lo. to ( self . prev_span ) , kind, attrs) )
860+ } else if self . eat_keyword ( kw:: Match ) {
861+ let match_sp = self . prev_span ;
862+ self . parse_match_expr ( attrs) . map_err ( |mut err| {
863+ err. span_label ( match_sp, "while parsing this match expression" ) ;
864+ err
865+ } )
866+ } else if self . eat_keyword ( kw:: Unsafe ) {
867+ self . parse_block_expr ( None , lo, BlockCheckMode :: Unsafe ( ast:: UserProvided ) , attrs)
868+ } else if self . is_do_catch_block ( ) {
869+ self . recover_do_catch ( attrs)
870+ } else if self . is_try_block ( ) {
871+ self . expect_keyword ( kw:: Try ) ?;
872+ self . parse_try_block ( lo, attrs)
873+ } else if self . eat_keyword ( kw:: Return ) {
874+ self . parse_return_expr ( attrs)
875+ } else if self . eat_keyword ( kw:: Break ) {
876+ self . parse_break_expr ( attrs)
877+ } else if self . eat_keyword ( kw:: Yield ) {
878+ self . parse_yield_expr ( attrs)
879+ } else if self . eat_keyword ( kw:: Let ) {
880+ self . parse_let_expr ( attrs)
881+ } else if !self . unclosed_delims . is_empty ( ) && self . check ( & token:: Semi ) {
882+ // Don't complain about bare semicolons after unclosed braces
883+ // recovery in order to keep the error count down. Fixing the
884+ // delimiters will possibly also fix the bare semicolon found in
885+ // expression context. For example, silence the following error:
886+ //
887+ // error: expected expression, found `;`
888+ // --> file.rs:2:13
889+ // |
890+ // 2 | foo(bar(;
891+ // | ^ expected expression
892+ self . bump ( ) ;
893+ Ok ( self . mk_expr_err ( self . token . span ) )
894+ } else if self . token . span . rust_2018 ( ) {
895+ // `Span::rust_2018()` is somewhat expensive; don't get it repeatedly.
896+ if self . check_keyword ( kw:: Async ) {
897+ if self . is_async_block ( ) { // Check for `async {` and `async move {`.
898+ self . parse_async_block ( attrs)
907899 } else {
908- self . parse_lit_expr ( attrs)
900+ self . parse_closure_expr ( attrs)
909901 }
902+ } else if self . eat_keyword ( kw:: Await ) {
903+ self . recover_incorrect_await_syntax ( lo, self . prev_span , attrs)
904+ } else {
905+ self . parse_lit_expr ( attrs)
910906 }
907+ } else {
908+ self . parse_lit_expr ( attrs)
911909 }
912910 }
913911
0 commit comments