File tree 1 file changed +11
-3
lines changed
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -488,7 +488,11 @@ impl MiscEarlyLints {
488
488
LitIntType :: Unsuffixed => "" ,
489
489
} ;
490
490
491
- let maybe_last_sep_idx = lit_snip. len ( ) - suffix. len ( ) - 1 ;
491
+ let maybe_last_sep_idx = if let Some ( val) = lit_snip. len ( ) . checked_sub ( suffix. len ( ) + 1 ) {
492
+ val
493
+ } else {
494
+ return ; // It's useless so shouldn't lint.
495
+ } ;
492
496
// Do not lint when literal is unsuffixed.
493
497
if !suffix. is_empty ( ) && lit_snip. as_bytes ( ) [ maybe_last_sep_idx] != b'_' {
494
498
span_lint_and_sugg (
@@ -502,7 +506,7 @@ impl MiscEarlyLints {
502
506
) ;
503
507
}
504
508
505
- if lit_snip. starts_with ( "0x" ) {
509
+ if lit_snip. starts_with ( "0x" ) && maybe_last_sep_idx >= 3 {
506
510
let mut seen = ( false , false ) ;
507
511
for ch in lit_snip. as_bytes ( ) [ 2 ..=maybe_last_sep_idx] . iter ( ) {
508
512
match ch {
@@ -546,7 +550,11 @@ impl MiscEarlyLints {
546
550
}
547
551
} else if let LitKind :: Float ( _, LitFloatType :: Suffixed ( float_ty) ) = lit. kind {
548
552
let suffix = float_ty. name_str ( ) ;
549
- let maybe_last_sep_idx = lit_snip. len ( ) - suffix. len ( ) - 1 ;
553
+ let maybe_last_sep_idx = if let Some ( val) = lit_snip. len ( ) . checked_sub ( suffix. len ( ) + 1 ) {
554
+ val
555
+ } else {
556
+ return ; // It's useless so shouldn't lint.
557
+ } ;
550
558
if lit_snip. as_bytes ( ) [ maybe_last_sep_idx] != b'_' {
551
559
span_lint_and_sugg (
552
560
cx,
You can’t perform that action at this time.
0 commit comments