@@ -10,8 +10,8 @@ use super::{
1010use crate :: errors:: {
1111 AssignmentElseNotAllowed , CompoundAssignmentExpressionInLet , ConstLetMutuallyExclusive ,
1212 DocCommentDoesNotDocumentAnything , ExpectedStatementAfterOuterAttr , InvalidCurlyInLetElse ,
13- InvalidExpressionInLetElse , InvalidVariableDeclaration , InvalidVariableDeclarationSub ,
14- WrapExpressionInParentheses ,
13+ InvalidExpressionInLetElse , InvalidIdentiferStartsWithNumber , InvalidVariableDeclaration ,
14+ InvalidVariableDeclarationSub , WrapExpressionInParentheses ,
1515} ;
1616use crate :: maybe_whole;
1717
@@ -264,6 +264,7 @@ impl<'a> Parser<'a> {
264264 self . bump ( ) ;
265265 }
266266
267+ self . report_invalid_identifier_error ( ) ?;
267268 let ( pat, colon) = self . parse_pat_before_ty ( None , RecoverComma :: Yes , "`let` bindings" ) ?;
268269
269270 let ( err, ty) = if colon {
@@ -355,6 +356,18 @@ impl<'a> Parser<'a> {
355356 Ok ( P ( ast:: Local { ty, pat, kind, id : DUMMY_NODE_ID , span : lo. to ( hi) , attrs, tokens : None } ) )
356357 }
357358
359+ /// report error for `let 1x = 123`
360+ pub fn report_invalid_identifier_error ( & mut self ) -> PResult < ' a , ( ) > {
361+ if let token:: Literal ( lit) = self . token . uninterpolate ( ) . kind &&
362+ let Err ( _) = rustc_ast:: Lit :: from_token ( & self . token ) &&
363+ ( lit. kind == token:: LitKind :: Integer || lit. kind == token:: LitKind :: Float ) &&
364+ self . look_ahead ( 1 , |t| matches ! ( t. kind, token:: Eq ) || matches ! ( t. kind, token:: Colon ) ) {
365+ let err = self . sess . create_err ( InvalidIdentiferStartsWithNumber { span : self . token . span } ) ;
366+ return Err ( err) ;
367+ }
368+ Ok ( ( ) )
369+ }
370+
358371 fn check_let_else_init_bool_expr ( & self , init : & ast:: Expr ) {
359372 if let ast:: ExprKind :: Binary ( op, ..) = init. kind {
360373 if op. node . lazy ( ) {
0 commit comments