Skip to content

Commit 85512e8

Browse files
committed
chore: clippy::unreadable_literal
improve readability by adding underscores to large numeric literals
1 parent f79673f commit 85512e8

7 files changed

Lines changed: 26 additions & 27 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,6 @@ should_panic_without_expect = "allow" # 2
688688
doc_markdown = "allow"
689689
unused_self = "allow"
690690
enum_glob_use = "allow"
691-
unreadable_literal = "allow"
692691
unnested_or_patterns = "allow"
693692
implicit_hasher = "allow"
694693
struct_field_names = "allow"

src/uucore/src/lib/features/format/num_format.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,11 +1128,11 @@ mod test {
11281128
ForceDecimal::No,
11291129
)
11301130
};
1131-
assert_eq!(f(0.1171875), "0.117188");
1132-
assert_eq!(f(0.01171875), "0.0117188");
1133-
assert_eq!(f(0.001171875), "0.00117187");
1134-
assert_eq!(f(0.0001171875), "0.000117187");
1135-
assert_eq!(f(0.001171875001), "0.00117188");
1131+
assert_eq!(f(0.117_187_5), "0.117188");
1132+
assert_eq!(f(0.011_718_75), "0.0117188");
1133+
assert_eq!(f(0.001_171_875), "0.00117187");
1134+
assert_eq!(f(0.000_117_187_5), "0.000117187");
1135+
assert_eq!(f(0.001_171_875_001), "0.00117188");
11361136
}
11371137

11381138
#[test]
@@ -1149,7 +1149,7 @@ mod test {
11491149
assert_eq!(f(0.001), "0.001");
11501150
assert_eq!(f(0.0001), "0.0001");
11511151
assert_eq!(f(0.00001), "1e-05");
1152-
assert_eq!(f(0.000001), "1e-06");
1152+
assert_eq!(f(0.000_001), "1e-06");
11531153
}
11541154

11551155
/// Wrapper function to get a string out of Format.fmt()

src/uucore/src/lib/features/parser/num_parser.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ mod tests {
583583
u64::extended_parse("-9223372036854775808") // i64::MIN
584584
);
585585
assert_eq!(
586-
Ok(1123372036854675616),
586+
Ok(1_123_372_036_854_675_616),
587587
u64::extended_parse("-17323372036854876000") // 2*i64::MIN
588588
);
589589
assert_eq!(Ok(1), u64::extended_parse("-18446744073709551615")); // -u64::MAX
@@ -679,10 +679,10 @@ mod tests {
679679
assert_eq!(Ok(123.15), f64::extended_parse("0123.15"));
680680
assert_eq!(Ok(123.15), f64::extended_parse("+0123.15"));
681681
assert_eq!(Ok(-123.15), f64::extended_parse("-0123.15"));
682-
assert_eq!(Ok(12315000.0), f64::extended_parse("123.15e5"));
683-
assert_eq!(Ok(-12315000.0), f64::extended_parse("-123.15e5"));
684-
assert_eq!(Ok(12315000.0), f64::extended_parse("123.15E+5"));
685-
assert_eq!(Ok(0.0012315), f64::extended_parse("123.15E-5"));
682+
assert_eq!(Ok(12_315_000.0), f64::extended_parse("123.15e5"));
683+
assert_eq!(Ok(-12_315_000.0), f64::extended_parse("-123.15e5"));
684+
assert_eq!(Ok(12_315_000.0), f64::extended_parse("123.15E+5"));
685+
assert_eq!(Ok(0.001_231_5), f64::extended_parse("123.15E-5"));
686686
assert_eq!(
687687
Ok(0.15),
688688
f64::extended_parse(".150000000000000000000000000231313")
@@ -933,7 +933,7 @@ mod tests {
933933

934934
// We cannot really check that 'e' is not a valid exponent indicator for hex floats...
935935
// but we can check that the number still gets parsed properly: 0x0.8e5 is 0x8e5 / 16**3
936-
assert_eq!(Ok(0.555908203125), f64::extended_parse("0x0.8e5"));
936+
assert_eq!(Ok(0.555_908_203_125), f64::extended_parse("0x0.8e5"));
937937

938938
assert_eq!(
939939
f64::extended_parse("0x0.1p"),

src/uucore/src/lib/features/parser/parse_time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn from_str(string: &str, allow_suffixes: bool) -> Result<Duration, String>
8787
return Ok(Duration::MAX);
8888
}
8989
// early return if number is too small (< 1 ns)
90-
if !bd.is_zero() && bd < bigdecimal::BigDecimal::from_f64(0.0000000001).unwrap() {
90+
if !bd.is_zero() && bd < bigdecimal::BigDecimal::from_f64(0.000_000_000_1).unwrap() {
9191
return Ok(NANOSECOND_DURATION);
9292
}
9393
bd

src/uucore/src/lib/features/sum.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ impl Crc {
175175
crc_fast::CrcParams::new(
176176
"CRC-32/CKSUM", // Name
177177
32, // Width
178-
0x04c11db7, // Polynomial
179-
0x00000000, // Initial CRC value: 0 (not 0xffffffff)
178+
0x04c1_1db7, // Polynomial
179+
0x0000_0000, // Initial CRC value: 0 (not 0xffffffff)
180180
false, // No input reflection (refin)
181-
0xffffffff, // XOR output with 0xffffffff (xorout)
181+
0xffff_ffff, // XOR output with 0xffffffff (xorout)
182182
0, // Check value (not used)
183183
)
184184
}
@@ -245,7 +245,7 @@ impl Digest for CRC32B {
245245
let result = self.digest.finalize();
246246
// crc_fast returns a 64-bit value, but CRC32B should be 32-bit
247247
// Take the lower 32 bits and convert to big-endian bytes
248-
let crc32_value = (result & 0xffffffff) as u32;
248+
let crc32_value = (result & 0xffff_ffff) as u32;
249249
out.copy_from_slice(&crc32_value.to_be_bytes());
250250
}
251251

@@ -601,7 +601,7 @@ mod tests {
601601
assert_ne!(empty_result, test_result);
602602

603603
// Test known value: "test" should give 3076352578
604-
assert_eq!(test_result, 3076352578);
604+
assert_eq!(test_result, 3_076_352_578);
605605
}
606606

607607
#[test]
@@ -653,9 +653,9 @@ mod tests {
653653
// Test against our CRC implementation values
654654
// Note: These are the correct values for our POSIX cksum implementation
655655
let test_cases = [
656-
("", 4294967295_u64),
657-
("a", 1220704766_u64),
658-
("abc", 1219131554_u64),
656+
("", 4_294_967_295_u64),
657+
("a", 1_220_704_766_u64),
658+
("abc", 1_219_131_554_u64),
659659
];
660660

661661
for (input, expected) in test_cases {

tests/by-util/test_dd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ fn test_skip_overflow() {
19011901
#[cfg(target_os = "linux")]
19021902
fn test_nocache_eof() {
19031903
let (at, mut ucmd) = at_and_ucmd!();
1904-
at.write_bytes("in.f", &vec![0u8; 1234567]);
1904+
at.write_bytes("in.f", &vec![0u8; 1_234_567]);
19051905
ucmd.args(&[
19061906
"if=in.f",
19071907
"of=out.f",
@@ -1910,15 +1910,15 @@ fn test_nocache_eof() {
19101910
"status=noxfer",
19111911
])
19121912
.succeeds();
1913-
assert_eq!(at.read_bytes("out.f").len(), 1234567);
1913+
assert_eq!(at.read_bytes("out.f").len(), 1_234_567);
19141914
}
19151915

19161916
#[test]
19171917
#[cfg(all(target_os = "linux", feature = "printf"))]
19181918
fn test_nocache_eof_fadvise_zero_length() {
19191919
use std::process::Command;
19201920
let (at, _ucmd) = at_and_ucmd!();
1921-
at.write_bytes("in.f", &vec![0u8; 1234567]);
1921+
at.write_bytes("in.f", &vec![0u8; 1_234_567]);
19221922

19231923
let strace_file = at.plus_as_string("strace.out");
19241924
let result = Command::new("strace")

tests/by-util/test_shred.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ fn test_shred_non_utf8_paths() {
339339
fn test_gnu_shred_passes_20() {
340340
let (at, mut ucmd) = at_and_ucmd!();
341341

342-
let us_data = vec![0x55; 102400]; // 100K of 'U' bytes
342+
let us_data = vec![0x55; 102_400]; // 100K of 'U' bytes
343343
at.write_bytes("Us", &us_data);
344344

345345
let file = "f";
@@ -397,7 +397,7 @@ fn test_gnu_shred_passes_20() {
397397
fn test_gnu_shred_passes_different_counts() {
398398
let (at, mut ucmd) = at_and_ucmd!();
399399

400-
let us_data = vec![0x55; 102400];
400+
let us_data = vec![0x55; 102_400];
401401
at.write_bytes("Us", &us_data);
402402

403403
let file = "f";

0 commit comments

Comments
 (0)