File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -488,7 +488,11 @@ impl MiscEarlyLints {
488488 LitIntType :: Unsuffixed => "" ,
489489 } ;
490490
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+ } ;
492496 // Do not lint when literal is unsuffixed.
493497 if !suffix. is_empty ( ) && lit_snip. as_bytes ( ) [ maybe_last_sep_idx] != b'_' {
494498 span_lint_and_sugg (
@@ -502,7 +506,7 @@ impl MiscEarlyLints {
502506 ) ;
503507 }
504508
505- if lit_snip. starts_with ( "0x" ) {
509+ if lit_snip. starts_with ( "0x" ) && maybe_last_sep_idx >= 3 {
506510 let mut seen = ( false , false ) ;
507511 for ch in lit_snip. as_bytes ( ) [ 2 ..=maybe_last_sep_idx] . iter ( ) {
508512 match ch {
@@ -546,7 +550,11 @@ impl MiscEarlyLints {
546550 }
547551 } else if let LitKind :: Float ( _, LitFloatType :: Suffixed ( float_ty) ) = lit. kind {
548552 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+ } ;
550558 if lit_snip. as_bytes ( ) [ maybe_last_sep_idx] != b'_' {
551559 span_lint_and_sugg (
552560 cx,
You can’t perform that action at this time.
0 commit comments