]> git.lizzy.rs Git - rust.git/commitdiff
mistyped_literal_suffixes: ignore floats without exponent
authorgoth-turtle <93494392+goth-turtle@users.noreply.github.com>
Sun, 24 Apr 2022 13:06:48 +0000 (15:06 +0200)
committergoth-turtle <93494392+goth-turtle@users.noreply.github.com>
Sun, 24 Apr 2022 13:28:36 +0000 (15:28 +0200)
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

clippy_lints/src/literal_representation.rs
tests/ui/mistyped_literal_suffix.fixed
tests/ui/mistyped_literal_suffix.rs
tests/ui/mistyped_literal_suffix.stderr

index 362d45991bb5406ad1d8f4a7eb035268a3a1e72c..269d3c62eafcd5d0e9692f80bfb27a250cbbc0d3 100644 (file)
@@ -308,7 +308,7 @@ fn check_for_mistyped_suffix(
         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)
         };
index a59384e0725d7af5086323c37ba17d2814b38211..a7b36d53cd26c7cc1011553d0a1ceb2fd88268ae 100644 (file)
@@ -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;
 }
index 01e425f9f1d7bf413c660a0de94ccebc774ab242..c97b31965c75a7c4cd1f3030dccd3b042f23fd7c 100644 (file)
@@ -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;
 }
index 6fcd1f2f180505274def9c7c61a8141014994554..fb761d9bde45255085e56a861d791d370516c251 100644 (file)
@@ -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`