Skip to content

Commit

Permalink
Auto merge of #7774 - dswij:useless-exponent, r=llogiq
Browse files Browse the repository at this point in the history
Useless exponent

Closes #7745

I'm open to some thoughts on dropping the exponents on suggestions when it's zero. I personally don't see any problem on this.

changelog: [`useless_exponent`] suggestion drops exponent when exponent value is zero
  • Loading branch information
bors committed Oct 6, 2021
2 parents 871b8b5 + e476d05 commit c6b9158
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
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

0 comments on commit c6b9158

Please sign in to comment.