diff options
| author | goth-turtle <93494392+goth-turtle@users.noreply.github.com> | 2022-04-24 15:06:48 +0200 |
|---|---|---|
| committer | goth-turtle <93494392+goth-turtle@users.noreply.github.com> | 2022-04-24 15:28:36 +0200 |
| commit | b4a50e9ee5adda55ad68b0dc637433fa0936e10e (patch) | |
| tree | 23f127646e39fd8fbbc54929834454fa8cd3bfb5 | |
| parent | f2902494614643509685c3bf974287ac9844b2fd (diff) | |
| download | rust-b4a50e9ee5adda55ad68b0dc637433fa0936e10e.tar.gz rust-b4a50e9ee5adda55ad68b0dc637433fa0936e10e.zip | |
mistyped_literal_suffixes: ignore floats without exponent
Previously this lint would only look at the integer part of floating point literals without an exponent, giving wrong suggestions like: ``` | 8 | let _ = 123_32.123; | ^^^^^^^^^^ help: did you mean to write: `123.123_f32` | ``` Instead, it now ignores these literals. Fixes #6129
| -rw-r--r-- | clippy_lints/src/literal_representation.rs | 2 | ||||
| -rw-r--r-- | tests/ui/mistyped_literal_suffix.fixed | 4 | ||||
| -rw-r--r-- | tests/ui/mistyped_literal_suffix.rs | 4 | ||||
| -rw-r--r-- | tests/ui/mistyped_literal_suffix.stderr | 2 |
4 files changed, 10 insertions, 2 deletions
diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 362d45991bb..269d3c62eaf 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -308,7 +308,7 @@ impl LiteralDigitGrouping { let (part, mistyped_suffixes, is_float) = if let Some((_, exponent)) = &mut num_lit.exponent { (exponent, &["32", "64"][..], true) } else if num_lit.fraction.is_some() { - (&mut num_lit.integer, &["32", "64"][..], true) + return true; } else { (&mut num_lit.integer, &["8", "16", "32", "64"][..], false) }; diff --git a/tests/ui/mistyped_literal_suffix.fixed b/tests/ui/mistyped_literal_suffix.fixed index a59384e0725..a7b36d53cd2 100644 --- a/tests/ui/mistyped_literal_suffix.fixed +++ b/tests/ui/mistyped_literal_suffix.fixed @@ -35,5 +35,9 @@ fn main() { let ok35 = 0x12345_16; let fail36 = 0xFFFF_FFFF_FFFF_FFFF_u64; // u64 + // issue #6129 + let ok37 = 123_32.123; + let ok38 = 124_64.0; + let _ = 1.123_45E1_f32; } diff --git a/tests/ui/mistyped_literal_suffix.rs b/tests/ui/mistyped_literal_suffix.rs index 01e425f9f1d..c97b31965c7 100644 --- a/tests/ui/mistyped_literal_suffix.rs +++ b/tests/ui/mistyped_literal_suffix.rs @@ -35,5 +35,9 @@ fn main() { let ok35 = 0x12345_16; let fail36 = 0xFFFF_FFFF_FFFF_FFFF_64; // u64 + // issue #6129 + let ok37 = 123_32.123; + let ok38 = 124_64.0; + let _ = 1.12345E1_32; } diff --git a/tests/ui/mistyped_literal_suffix.stderr b/tests/ui/mistyped_literal_suffix.stderr index 6fcd1f2f180..fb761d9bde4 100644 --- a/tests/ui/mistyped_literal_suffix.stderr +++ b/tests/ui/mistyped_literal_suffix.stderr @@ -91,7 +91,7 @@ LL | let fail36 = 0xFFFF_FFFF_FFFF_FFFF_64; // u64 | ^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to write: `0xFFFF_FFFF_FFFF_FFFF_u64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:38:13 + --> $DIR/mistyped_literal_suffix.rs:42:13 | LL | let _ = 1.12345E1_32; | ^^^^^^^^^^^^ help: did you mean to write: `1.123_45E1_f32` |
