]> git.lizzy.rs Git - rust.git/commitdiff
Do not lint float fractions in `mistyped_literal_suffixes` (fixes #4706)
authorFliegendeWurst <2012gdwu@web.de>
Mon, 5 Oct 2020 10:08:57 +0000 (12:08 +0200)
committerFliegendeWurst <2012gdwu@web.de>
Mon, 5 Oct 2020 10:09:21 +0000 (12:09 +0200)
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 a36fdca5d5de6a5816d8ff369501fad9c651b3dd..c54103b25c20e772f401a1cdcb6bc587d6d61fbe 100644 (file)
@@ -264,13 +264,10 @@ fn check_for_mistyped_suffix(
 
         let (part, mistyped_suffixes, missing_char) = if let Some((_, exponent)) = &mut num_lit.exponent {
             (exponent, &["32", "64"][..], 'f')
+        } else if num_lit.fraction.is_some() {
+            (&mut num_lit.integer, &["32", "64"][..], 'f')
         } else {
-            num_lit
-                .fraction
-                .as_mut()
-                .map_or((&mut num_lit.integer, &["8", "16", "32", "64"][..], 'i'), |fraction| {
-                    (fraction, &["32", "64"][..], 'f')
-                })
+            (&mut num_lit.integer, &["8", "16", "32", "64"][..], 'i')
         };
 
         let mut split = part.rsplit('_');
index baee77357303814e749dbc3c9909368b4e531125..8275bfa5db7108b32ad7c99211855579a521e1fd 100644 (file)
@@ -1,6 +1,6 @@
 // run-rustfix
 
-#![allow(dead_code, unused_variables, clippy::excessive_precision)]
+#![allow(dead_code, unused_variables, clippy::excessive_precision, clippy::inconsistent_digit_grouping)]
 
 fn main() {
     let fail14 = 2_i32;
@@ -12,13 +12,13 @@ fn main() {
     let fail20 = 2_i8; //
     let fail21 = 4_i16; //
 
-    let fail24 = 12.34_f64;
+    let ok24 = 12.34_64;
     let fail25 = 1E2_f32;
     let fail26 = 43E7_f64;
     let fail27 = 243E17_f32;
     #[allow(overflowing_literals)]
     let fail28 = 241_251_235E723_f64;
-    let fail29 = 42_279.911_f32;
+    let ok29 = 42279.911_32;
 
     let _ = 1.123_45E1_f32;
 }
index 6de447f40214b527083054f64874989a93c984f5..8a451807aeb4c2a1aaed6978646ba67bf4bb3237 100644 (file)
@@ -1,6 +1,6 @@
 // run-rustfix
 
-#![allow(dead_code, unused_variables, clippy::excessive_precision)]
+#![allow(dead_code, unused_variables, clippy::excessive_precision, clippy::inconsistent_digit_grouping)]
 
 fn main() {
     let fail14 = 2_32;
@@ -12,13 +12,13 @@ fn main() {
     let fail20 = 2__8; //
     let fail21 = 4___16; //
 
-    let fail24 = 12.34_64;
+    let ok24 = 12.34_64;
     let fail25 = 1E2_32;
     let fail26 = 43E7_64;
     let fail27 = 243E17_32;
     #[allow(overflowing_literals)]
     let fail28 = 241251235E723_64;
-    let fail29 = 42279.911_32;
+    let ok29 = 42279.911_32;
 
     let _ = 1.12345E1_32;
 }
index 48a7ae904948c279c8c121e04526ce991e48888d..f4c5adfe82c2fbe9a5e6112072c5ccb487eb104a 100644 (file)
@@ -36,12 +36,6 @@ error: mistyped literal suffix
 LL |     let fail21 = 4___16; //
    |                  ^^^^^^ help: did you mean to write: `4_i16`
 
-error: mistyped literal suffix
-  --> $DIR/mistyped_literal_suffix.rs:15:18
-   |
-LL |     let fail24 = 12.34_64;
-   |                  ^^^^^^^^ help: did you mean to write: `12.34_f64`
-
 error: mistyped literal suffix
   --> $DIR/mistyped_literal_suffix.rs:16:18
    |
@@ -66,17 +60,11 @@ error: mistyped literal suffix
 LL |     let fail28 = 241251235E723_64;
    |                  ^^^^^^^^^^^^^^^^ help: did you mean to write: `241_251_235E723_f64`
 
-error: mistyped literal suffix
-  --> $DIR/mistyped_literal_suffix.rs:21:18
-   |
-LL |     let fail29 = 42279.911_32;
-   |                  ^^^^^^^^^^^^ help: did you mean to write: `42_279.911_f32`
-
 error: mistyped literal suffix
   --> $DIR/mistyped_literal_suffix.rs:23:13
    |
 LL |     let _ = 1.12345E1_32;
    |             ^^^^^^^^^^^^ help: did you mean to write: `1.123_45E1_f32`
 
-error: aborting due to 13 previous errors
+error: aborting due to 11 previous errors