@@ -10,8 +10,8 @@ use super::{
10
10
use crate :: errors:: {
11
11
AssignmentElseNotAllowed , CompoundAssignmentExpressionInLet , ConstLetMutuallyExclusive ,
12
12
DocCommentDoesNotDocumentAnything , ExpectedStatementAfterOuterAttr , InvalidCurlyInLetElse ,
13
- InvalidExpressionInLetElse , InvalidVariableDeclaration , InvalidVariableDeclarationSub ,
14
- WrapExpressionInParentheses ,
13
+ InvalidExpressionInLetElse , InvalidIdentiferStartsWithNumber , InvalidVariableDeclaration ,
14
+ InvalidVariableDeclarationSub , WrapExpressionInParentheses ,
15
15
} ;
16
16
use crate :: maybe_whole;
17
17
@@ -264,6 +264,7 @@ impl<'a> Parser<'a> {
264
264
self . bump ( ) ;
265
265
}
266
266
267
+ self . report_invalid_identifier_error ( ) ?;
267
268
let ( pat, colon) = self . parse_pat_before_ty ( None , RecoverComma :: Yes , "`let` bindings" ) ?;
268
269
269
270
let ( err, ty) = if colon {
@@ -355,6 +356,18 @@ impl<'a> Parser<'a> {
355
356
Ok ( P ( ast:: Local { ty, pat, kind, id : DUMMY_NODE_ID , span : lo. to ( hi) , attrs, tokens : None } ) )
356
357
}
357
358
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
+
358
371
fn check_let_else_init_bool_expr ( & self , init : & ast:: Expr ) {
359
372
if let ast:: ExprKind :: Binary ( op, ..) = init. kind {
360
373
if op. node . lazy ( ) {
0 commit comments