Skip to content

Fix false positive in zero_prefixed_literal #5170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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