@@ -38,7 +38,7 @@ use rustc_errors::{
38
38
use rustc_session:: errors:: ExprParenthesesNeeded ;
39
39
use rustc_span:: source_map:: Spanned ;
40
40
use rustc_span:: symbol:: { kw, sym, Ident } ;
41
- use rustc_span:: { Span , SpanSnippetError , DUMMY_SP } ;
41
+ use rustc_span:: { Span , SpanSnippetError , Symbol , DUMMY_SP } ;
42
42
use std:: mem:: take;
43
43
use std:: ops:: { Deref , DerefMut } ;
44
44
use thin_vec:: { thin_vec, ThinVec } ;
@@ -309,8 +309,11 @@ impl<'a> Parser<'a> {
309
309
&& self . look_ahead ( 1 , |t| t. is_ident ( ) ) )
310
310
. then_some ( SuggRemoveComma { span : self . token . span } ) ;
311
311
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
+ } ) ;
314
317
315
318
let err = ExpectedIdentifier {
316
319
span : self . token . span ,
@@ -378,13 +381,24 @@ impl<'a> Parser<'a> {
378
381
379
382
/// Checks if the current token is a integer or float literal and looks like
380
383
/// 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
+ }
388
402
}
389
403
390
404
pub ( super ) fn expected_one_of_not_found (
0 commit comments