@@ -38,7 +38,7 @@ use rustc_errors::{
3838use rustc_session:: errors:: ExprParenthesesNeeded ;
3939use rustc_span:: source_map:: Spanned ;
4040use rustc_span:: symbol:: { kw, sym, Ident } ;
41- use rustc_span:: { Span , SpanSnippetError , DUMMY_SP } ;
41+ use rustc_span:: { Span , SpanSnippetError , Symbol , DUMMY_SP } ;
4242use std:: mem:: take;
4343use std:: ops:: { Deref , DerefMut } ;
4444use thin_vec:: { thin_vec, ThinVec } ;
@@ -309,8 +309,11 @@ impl<'a> Parser<'a> {
309309 && self . look_ahead ( 1 , |t| t. is_ident ( ) ) )
310310 . then_some ( SuggRemoveComma { span : self . token . span } ) ;
311311
312- let help_cannot_start_number =
313- self . is_lit_bad_ident ( ) . then_some ( HelpIdentifierStartsWithNumber ) ;
312+ let help_cannot_start_number = self . is_lit_bad_ident ( ) . map ( |( len, _valid_portion) | {
313+ let ( invalid, _valid) = self . token . span . split_at ( len as u32 ) ;
314+
315+ HelpIdentifierStartsWithNumber { num_span : invalid }
316+ } ) ;
314317
315318 let err = ExpectedIdentifier {
316319 span : self . token . span ,
@@ -378,13 +381,24 @@ impl<'a> Parser<'a> {
378381
379382 /// Checks if the current token is a integer or float literal and looks like
380383 /// it could be a invalid identifier with digits at the start.
381- pub ( super ) fn is_lit_bad_ident ( & mut self ) -> bool {
382- matches ! ( self . token. uninterpolate( ) . kind, token:: Literal ( Lit { kind: token:: LitKind :: Integer | token:: LitKind :: Float , .. } )
383- // ensure that the integer literal is followed by a *invalid*
384- // suffix: this is how we know that it is a identifier with an
385- // invalid beginning.
386- if rustc_ast:: MetaItemLit :: from_token( & self . token) . is_none( )
387- )
384+ ///
385+ /// Returns the number of characters (bytes) composing the invalid portion
386+ /// of the identifier and the valid portion of the identifier.
387+ pub ( super ) fn is_lit_bad_ident ( & mut self ) -> Option < ( usize , Symbol ) > {
388+ // ensure that the integer literal is followed by a *invalid*
389+ // suffix: this is how we know that it is a identifier with an
390+ // invalid beginning.
391+ if let token:: Literal ( Lit {
392+ kind : token:: LitKind :: Integer | token:: LitKind :: Float ,
393+ symbol,
394+ suffix,
395+ } ) = self . token . uninterpolate ( ) . kind
396+ && rustc_ast:: MetaItemLit :: from_token ( & self . token ) . is_none ( )
397+ {
398+ Some ( ( symbol. as_str ( ) . len ( ) , suffix. unwrap ( ) ) )
399+ } else {
400+ None
401+ }
388402 }
389403
390404 pub ( super ) fn expected_one_of_not_found (
0 commit comments