Skip to content

Commit 06777d5

Browse files
committed
Auto merge of rust-lang#5170 - JohnTitor:fix-prefix, r=flip1995
Fix false positive in `zero_prefixed_literal` Fixes rust-lang#5169 changelog: Fix false positive in `zero_prefixed_literal`
2 parents f8576c7 + f77158b commit 06777d5

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

clippy_lints/src/misc_early.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,11 @@ impl MiscEarlyLints {
506506
);
507507
}
508508

509-
if lit_snip.starts_with("0x") && maybe_last_sep_idx >= 3 {
509+
if lit_snip.starts_with("0x") {
510+
if maybe_last_sep_idx <= 2 {
511+
// It's meaningless or causes range error.
512+
return;
513+
}
510514
let mut seen = (false, false);
511515
for ch in lit_snip.as_bytes()[2..=maybe_last_sep_idx].iter() {
512516
match ch {

tests/ui/literals.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ fn main() {
2828
let ok15 = 0xab_cabc_abca_bcab_cabc;
2929
let ok16 = 0xFE_BAFE_ABAB_ABCD;
3030
let ok17 = 0x123_4567_8901_usize;
31+
let ok18 = 0xF;
3132

3233
let fail19 = 12_3456_21;
3334
let fail22 = 3__4___23;

tests/ui/literals.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,21 @@ LL | let fail8 = 0o123;
5050
| ^^^^^
5151

5252
error: digits grouped inconsistently by underscores
53-
--> $DIR/literals.rs:32:18
53+
--> $DIR/literals.rs:33:18
5454
|
5555
LL | let fail19 = 12_3456_21;
5656
| ^^^^^^^^^^ help: consider: `12_345_621`
5757
|
5858
= note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings`
5959

6060
error: digits grouped inconsistently by underscores
61-
--> $DIR/literals.rs:33:18
61+
--> $DIR/literals.rs:34:18
6262
|
6363
LL | let fail22 = 3__4___23;
6464
| ^^^^^^^^^ help: consider: `3_423`
6565

6666
error: digits grouped inconsistently by underscores
67-
--> $DIR/literals.rs:34:18
67+
--> $DIR/literals.rs:35:18
6868
|
6969
LL | let fail23 = 3__16___23;
7070
| ^^^^^^^^^^ help: consider: `31_623`

0 commit comments

Comments
 (0)