Skip to content

Commit

Permalink
Auto merge of rust-lang#5170 - JohnTitor:fix-prefix, r=flip1995
Browse files Browse the repository at this point in the history
Fix false positive in `zero_prefixed_literal`

Fixes rust-lang#5169

changelog: Fix false positive in `zero_prefixed_literal`
  • Loading branch information
bors committed Feb 13, 2020
2 parents f8576c7 + f77158b commit 06777d5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion clippy_lints/src/misc_early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,11 @@ impl MiscEarlyLints {
);
}

if lit_snip.starts_with("0x") && maybe_last_sep_idx >= 3 {
if lit_snip.starts_with("0x") {
if maybe_last_sep_idx <= 2 {
// It's meaningless or causes range error.
return;
}
let mut seen = (false, false);
for ch in lit_snip.as_bytes()[2..=maybe_last_sep_idx].iter() {
match ch {
Expand Down
1 change: 1 addition & 0 deletions tests/ui/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn main() {
let ok15 = 0xab_cabc_abca_bcab_cabc;
let ok16 = 0xFE_BAFE_ABAB_ABCD;
let ok17 = 0x123_4567_8901_usize;
let ok18 = 0xF;

let fail19 = 12_3456_21;
let fail22 = 3__4___23;
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/literals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ LL | let fail8 = 0o123;
| ^^^^^

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

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

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

0 comments on commit 06777d5

Please sign in to comment.