mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Change unusual_byte_groupings to require byte groupings of equal size
This commit is contained in:
parent
5b6795f50b
commit
f12b492ee0
6 changed files with 17 additions and 39 deletions
|
@ -210,7 +210,7 @@ impl WarningType {
|
||||||
cx,
|
cx,
|
||||||
UNUSUAL_BYTE_GROUPINGS,
|
UNUSUAL_BYTE_GROUPINGS,
|
||||||
span,
|
span,
|
||||||
"digits of hex or binary literal not grouped by four",
|
"digits of hex, binary or octal literal not in groups of equal size",
|
||||||
"consider",
|
"consider",
|
||||||
suggested_format,
|
suggested_format,
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
|
@ -427,8 +427,12 @@ impl LiteralDigitGrouping {
|
||||||
|
|
||||||
let first = groups.next().expect("At least one group");
|
let first = groups.next().expect("At least one group");
|
||||||
|
|
||||||
if (radix == Radix::Binary || radix == Radix::Hexadecimal) && groups.any(|i| i != 4 && i != 2) {
|
if radix == Radix::Binary || radix == Radix::Octal || radix == Radix::Hexadecimal {
|
||||||
return Err(WarningType::UnusualByteGroupings);
|
if let Some(second_size) = groups.next() {
|
||||||
|
if !groups.all(|i| i == second_size) || first > second_size {
|
||||||
|
return Err(WarningType::UnusualByteGroupings);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(second) = groups.next() {
|
if let Some(second) = groups.next() {
|
||||||
|
|
|
@ -11,7 +11,7 @@ fn main() {
|
||||||
let _good = (
|
let _good = (
|
||||||
0b1011_i64,
|
0b1011_i64,
|
||||||
0o1_234_u32,
|
0o1_234_u32,
|
||||||
0x0123_4567,
|
0x1_234_567,
|
||||||
1_2345_6789,
|
1_2345_6789,
|
||||||
1234_f32,
|
1234_f32,
|
||||||
1_234.12_f32,
|
1_234.12_f32,
|
||||||
|
@ -19,7 +19,7 @@ fn main() {
|
||||||
1.123_4_f32,
|
1.123_4_f32,
|
||||||
);
|
);
|
||||||
let _bad = (
|
let _bad = (
|
||||||
0b11_0110_i64,
|
0b1_10110_i64,
|
||||||
0xdead_beef_usize,
|
0xdead_beef_usize,
|
||||||
123_456_f32,
|
123_456_f32,
|
||||||
123_456.12_f32,
|
123_456.12_f32,
|
||||||
|
|
|
@ -1,22 +1,10 @@
|
||||||
error: digits of hex or binary literal not grouped by four
|
error: digits of hex, binary or octal literal not in groups of equal size
|
||||||
--> $DIR/large_digit_groups.rs:14:9
|
|
||||||
|
|
|
||||||
LL | 0x1_234_567,
|
|
||||||
| ^^^^^^^^^^^ help: consider: `0x0123_4567`
|
|
||||||
|
|
|
||||||
= note: `-D clippy::unusual-byte-groupings` implied by `-D warnings`
|
|
||||||
|
|
||||||
error: digits of hex or binary literal not grouped by four
|
|
||||||
--> $DIR/large_digit_groups.rs:22:9
|
|
||||||
|
|
|
||||||
LL | 0b1_10110_i64,
|
|
||||||
| ^^^^^^^^^^^^^ help: consider: `0b11_0110_i64`
|
|
||||||
|
|
||||||
error: digits of hex or binary literal not grouped by four
|
|
||||||
--> $DIR/large_digit_groups.rs:23:9
|
--> $DIR/large_digit_groups.rs:23:9
|
||||||
|
|
|
|
||||||
LL | 0xd_e_adbee_f_usize,
|
LL | 0xd_e_adbee_f_usize,
|
||||||
| ^^^^^^^^^^^^^^^^^^^ help: consider: `0xdead_beef_usize`
|
| ^^^^^^^^^^^^^^^^^^^ help: consider: `0xdead_beef_usize`
|
||||||
|
|
|
||||||
|
= note: `-D clippy::unusual-byte-groupings` implied by `-D warnings`
|
||||||
|
|
||||||
error: digit groups should be smaller
|
error: digit groups should be smaller
|
||||||
--> $DIR/large_digit_groups.rs:24:9
|
--> $DIR/large_digit_groups.rs:24:9
|
||||||
|
@ -44,5 +32,5 @@ error: digit groups should be smaller
|
||||||
LL | 1_23456.12345_6_f64,
|
LL | 1_23456.12345_6_f64,
|
||||||
| ^^^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_456_f64`
|
| ^^^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_456_f64`
|
||||||
|
|
||||||
error: aborting due to 7 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ error: digits grouped inconsistently by underscores
|
||||||
LL | let fail23 = 3__16___23;
|
LL | let fail23 = 3__16___23;
|
||||||
| ^^^^^^^^^^ help: consider: `31_623`
|
| ^^^^^^^^^^ help: consider: `31_623`
|
||||||
|
|
||||||
error: digits of hex or binary literal not grouped by four
|
error: digits of hex, binary or octal literal not in groups of equal size
|
||||||
--> $DIR/literals.rs:38:18
|
--> $DIR/literals.rs:38:18
|
||||||
|
|
|
|
||||||
LL | let fail24 = 0xAB_ABC_AB;
|
LL | let fail24 = 0xAB_ABC_AB;
|
||||||
|
@ -129,12 +129,6 @@ LL | let fail24 = 0xAB_ABC_AB;
|
||||||
|
|
|
|
||||||
= note: `-D clippy::unusual-byte-groupings` implied by `-D warnings`
|
= note: `-D clippy::unusual-byte-groupings` implied by `-D warnings`
|
||||||
|
|
||||||
error: digits of hex or binary literal not grouped by four
|
|
||||||
--> $DIR/literals.rs:39:18
|
|
||||||
|
|
|
||||||
LL | let fail25 = 0b01_100_101;
|
|
||||||
| ^^^^^^^^^^^^ help: consider: `0b0110_0101`
|
|
||||||
|
|
||||||
error: this is a decimal constant
|
error: this is a decimal constant
|
||||||
--> $DIR/literals.rs:46:13
|
--> $DIR/literals.rs:46:13
|
||||||
|
|
|
|
||||||
|
@ -168,5 +162,5 @@ help: if you mean to use a decimal constant, remove the `0` to avoid confusion
|
||||||
LL | let _ = 89;
|
LL | let _ = 89;
|
||||||
| ~~
|
| ~~
|
||||||
|
|
||||||
error: aborting due to 21 previous errors
|
error: aborting due to 20 previous errors
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ fn main() {
|
||||||
let _good = (
|
let _good = (
|
||||||
0b1011_i64,
|
0b1011_i64,
|
||||||
0o1_234_u32,
|
0o1_234_u32,
|
||||||
0x0123_4567,
|
0x1_234_567,
|
||||||
65536,
|
65536,
|
||||||
1_2345_6789,
|
1_2345_6789,
|
||||||
1234_f32,
|
1234_f32,
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
error: digits of hex or binary literal not grouped by four
|
|
||||||
--> $DIR/unreadable_literal.rs:26:9
|
|
||||||
|
|
|
||||||
LL | 0x1_234_567,
|
|
||||||
| ^^^^^^^^^^^ help: consider: `0x0123_4567`
|
|
||||||
|
|
|
||||||
= note: `-D clippy::unusual-byte-groupings` implied by `-D warnings`
|
|
||||||
|
|
||||||
error: long literal lacking separators
|
error: long literal lacking separators
|
||||||
--> $DIR/unreadable_literal.rs:34:17
|
--> $DIR/unreadable_literal.rs:34:17
|
||||||
|
|
|
|
||||||
|
@ -68,5 +60,5 @@ error: long literal lacking separators
|
||||||
LL | let _fail5 = 1.100300400;
|
LL | let _fail5 = 1.100300400;
|
||||||
| ^^^^^^^^^^^ help: consider: `1.100_300_400`
|
| ^^^^^^^^^^^ help: consider: `1.100_300_400`
|
||||||
|
|
||||||
error: aborting due to 11 previous errors
|
error: aborting due to 10 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue