diff options
| author | bors <bors@rust-lang.org> | 2024-07-16 12:56:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-16 12:56:10 +0000 |
| commit | 0ee9f44568b60aaef5d04684cb08f112edd89542 (patch) | |
| tree | ba07607fb70ddadffe7b58c83ed7dd4ab4843ced | |
| parent | eb4d88e690c431691bc0fd8eaa9f7096ecc2a723 (diff) | |
| parent | 489a77831ce61e3e3679f4fbcf93be42d3922e52 (diff) | |
| download | rust-0ee9f44568b60aaef5d04684cb08f112edd89542.tar.gz rust-0ee9f44568b60aaef5d04684cb08f112edd89542.zip | |
Auto merge of #13096 - apoisternex:issue12954, r=y21
fix [`excessive_precision`] suggestions on floats written in scientific notation fixes #12954 changelog: fix [`excessive_precision`] suggestions on float literal written in scientific notation
| -rw-r--r-- | clippy_utils/src/numeric_literal.rs | 2 | ||||
| -rw-r--r-- | tests/ui/excessive_precision.fixed | 4 | ||||
| -rw-r--r-- | tests/ui/excessive_precision.rs | 4 | ||||
| -rw-r--r-- | tests/ui/excessive_precision.stderr | 8 |
4 files changed, 17 insertions, 1 deletions
diff --git a/clippy_utils/src/numeric_literal.rs b/clippy_utils/src/numeric_literal.rs index bbe4149fe2a..c5a34160e3d 100644 --- a/clippy_utils/src/numeric_literal.rs +++ b/clippy_utils/src/numeric_literal.rs @@ -164,6 +164,8 @@ impl<'a> NumericLiteral<'a> { if !exponent.is_empty() && exponent != "0" { output.push_str(separator); Self::group_digits(&mut output, exponent, group_size, true, false); + } else if exponent == "0" && self.fraction.is_none() && self.suffix.is_none() { + output.push_str(".0"); } } diff --git a/tests/ui/excessive_precision.fixed b/tests/ui/excessive_precision.fixed index cc553103530..372f64f7d99 100644 --- a/tests/ui/excessive_precision.fixed +++ b/tests/ui/excessive_precision.fixed @@ -78,4 +78,8 @@ fn main() { const NEG_INF1: f32 = -1.0e+33f32; const NEG_INF2: f64 = -1.0e+3300f64; const NEG_INF3: f32 = -3.40282357e+38_f32; + + // issue #12954 + const _: f64 = 3.0; + const _: f64 = 3.0000000000000000; } diff --git a/tests/ui/excessive_precision.rs b/tests/ui/excessive_precision.rs index fff986a8296..1e40efbf245 100644 --- a/tests/ui/excessive_precision.rs +++ b/tests/ui/excessive_precision.rs @@ -78,4 +78,8 @@ fn main() { const NEG_INF1: f32 = -1.0e+33f32; const NEG_INF2: f64 = -1.0e+3300f64; const NEG_INF3: f32 = -3.40282357e+38_f32; + + // issue #12954 + const _: f64 = 3.0000000000000000e+00; + const _: f64 = 3.0000000000000000; } diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr index 22dd96e53bd..6d8e166a649 100644 --- a/tests/ui/excessive_precision.stderr +++ b/tests/ui/excessive_precision.stderr @@ -91,5 +91,11 @@ error: float has excessive precision 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 +error: float has excessive precision + --> tests/ui/excessive_precision.rs:83:20 + | +LL | const _: f64 = 3.0000000000000000e+00; + | ^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `3.0` + +error: aborting due to 16 previous errors |
