Skip to content
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

Drop exponent on suggestion when exponent value is zero #7774

Merged
merged 2 commits into from
Oct 6, 2021
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: 4 additions & 2 deletions clippy_utils/src/numeric_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ impl<'a> NumericLiteral<'a> {
}

if let Some((separator, exponent)) = self.exponent {
output.push_str(separator);
Self::group_digits(&mut output, exponent, group_size, true, false);
if exponent != "0" {
output.push_str(separator);
Self::group_digits(&mut output, exponent, group_size, true, false);
}
}

if let Some(suffix) = self.suffix {
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/excessive_precision.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ fn main() {

// issue #7744
let _ = 2.225_073_858_507_201e-308_f64;

// issue #7745
let _ = 0_f64;
}
3 changes: 3 additions & 0 deletions tests/ui/excessive_precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ fn main() {

// issue #7744
let _ = 2.225_073_858_507_201_1e-308_f64;

// issue #7745
let _ = 1.000_000_000_000_001e-324_f64;
}
8 changes: 7 additions & 1 deletion tests/ui/excessive_precision.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,11 @@ error: float has excessive precision
LL | let _ = 2.225_073_858_507_201_1e-308_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64`

error: aborting due to 14 previous errors
error: float has excessive precision
--> $DIR/excessive_precision.rs:68:13
|
LL | let _ = 1.000_000_000_000_001e-324_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0_f64`

error: aborting due to 15 previous errors