Skip to content

Commit

Permalink
literal representation: simplification
Browse files Browse the repository at this point in the history
Simplify calculation in grouping. Add test case to ensure `count()`
can't be zero in that branch.
  • Loading branch information
Michael Wright committed Nov 14, 2019
1 parent 2e9d173 commit 75e2dcf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/literal_representation.rs
Expand Up @@ -268,7 +268,7 @@ impl<'a> NumericLiteral<'a> {
let first_group_size;

if partial_group_first {
first_group_size = (digits.clone().count() + group_size - 1) % group_size + 1;
first_group_size = (digits.clone().count() - 1) % group_size + 1;
if pad {
for _ in 0..group_size - first_group_size {
output.push('0');
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/inconsistent_digit_grouping.fixed
Expand Up @@ -18,4 +18,7 @@ fn main() {
let _ = 0x0100_0000;
let _ = 0x1000_0000;
let _ = 0x0001_0000_0000_u64;

// Test suggestion when fraction has no digits
let _: f32 = 123_456.;
}
3 changes: 3 additions & 0 deletions tests/ui/inconsistent_digit_grouping.rs
Expand Up @@ -18,4 +18,7 @@ fn main() {
let _ = 0x1000000;
let _ = 0x10000000;
let _ = 0x100000000_u64;

// Test suggestion when fraction has no digits
let _: f32 = 1_23_456.;
}
8 changes: 7 additions & 1 deletion tests/ui/inconsistent_digit_grouping.stderr
Expand Up @@ -56,5 +56,11 @@ error: long literal lacking separators
LL | let _ = 0x100000000_u64;
| ^^^^^^^^^^^^^^^ help: consider: `0x0001_0000_0000_u64`

error: aborting due to 9 previous errors
error: digits grouped inconsistently by underscores
--> $DIR/inconsistent_digit_grouping.rs:23:18
|
LL | let _: f32 = 1_23_456.;
| ^^^^^^^^^ help: consider: `123_456.`

error: aborting due to 10 previous errors

0 comments on commit 75e2dcf

Please sign in to comment.