about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKrishna Sai Veera Reddy <veerareddy@email.arizona.edu>2020-02-16 23:55:16 -0800
committerKrishna Sai Veera Reddy <veerareddy@email.arizona.edu>2020-02-17 00:05:50 -0800
commit552452873ce393a0543de7d1cb6356dc0888d551 (patch)
tree4046ccf16ce8e01ef2219003a5c52c9406d5f037
parent0532f3e521293d4fa01518a238ea61665b11a3aa (diff)
downloadrust-552452873ce393a0543de7d1cb6356dc0888d551.tar.gz
rust-552452873ce393a0543de7d1cb6356dc0888d551.zip
Add tests for lossy whole number float literals
-rw-r--r--tests/ui/excessive_precision.fixed32
-rw-r--r--tests/ui/excessive_precision.rs22
-rw-r--r--tests/ui/excessive_precision.stderr78
3 files changed, 121 insertions, 11 deletions
diff --git a/tests/ui/excessive_precision.fixed b/tests/ui/excessive_precision.fixed
index 1646dff9064..f32307ce910 100644
--- a/tests/ui/excessive_precision.fixed
+++ b/tests/ui/excessive_precision.fixed
@@ -12,12 +12,12 @@ fn main() {
     const GOOD64_SM: f32 = 0.000_000_000_000_000_1;
     const GOOD64_DOT: f32 = 10_000_000_000_000_000.0;
 
-    const BAD32_1: f32 = 0.123_456_79;
+    const BAD32_1: f32 = 0.123_456_79_f32;
     const BAD32_2: f32 = 0.123_456_79;
     const BAD32_3: f32 = 0.1;
     const BAD32_EDGE: f32 = 1.000_001;
 
-    const BAD64_1: f64 = 0.123_456_789_012_345_66;
+    const BAD64_1: f64 = 0.123_456_789_012_345_66_f64;
     const BAD64_2: f64 = 0.123_456_789_012_345_66;
     const BAD64_3: f64 = 0.1;
 
@@ -34,11 +34,11 @@ fn main() {
     let good64_inf = 0.123_456_789_012;
 
     let bad32: f32 = 1.123_456_8;
-    let bad32_suf: f32 = 1.123_456_8;
-    let bad32_inf = 1.123_456_8;
+    let bad32_suf: f32 = 1.123_456_8_f32;
+    let bad32_inf = 1.123_456_8_f32;
 
     let bad64: f64 = 0.123_456_789_012_345_66;
-    let bad64_suf: f64 = 0.123_456_789_012_345_66;
+    let bad64_suf: f64 = 0.123_456_789_012_345_66_f64;
     let bad64_inf = 0.123_456_789_012_345_66;
 
     // Vectors
@@ -60,4 +60,26 @@ fn main() {
 
     // issue #2840
     let num = 0.000_000_000_01e-10f64;
+
+    // Lossy whole-number float literals
+    let _: f32 = 16_777_216.0;
+    let _: f32 = 16_777_220.0;
+    let _: f32 = 16_777_220.0;
+    let _: f32 = 16_777_220.0;
+    let _ = 16_777_220.0_f32;
+    let _: f32 = -16_777_220.0;
+    let _: f64 = 9_007_199_254_740_992.0;
+    let _: f64 = 9_007_199_254_740_992.0;
+    let _: f64 = 9_007_199_254_740_992.0;
+    let _ = 9_007_199_254_740_992.0_f64;
+    let _: f64 = -9_007_199_254_740_992.0;
+
+    // Lossless whole number float literals
+    let _: f32 = 16_777_216.0;
+    let _: f32 = 16_777_218.0;
+    let _: f32 = 16_777_220.0;
+    let _: f32 = -16_777_216.0;
+    let _: f32 = -16_777_220.0;
+    let _: f64 = 9_007_199_254_740_992.0;
+    let _: f64 = -9_007_199_254_740_992.0;
 }
diff --git a/tests/ui/excessive_precision.rs b/tests/ui/excessive_precision.rs
index ce4722a90f9..a3d31740027 100644
--- a/tests/ui/excessive_precision.rs
+++ b/tests/ui/excessive_precision.rs
@@ -60,4 +60,26 @@ fn main() {
 
     // issue #2840
     let num = 0.000_000_000_01e-10f64;
+
+    // Lossy whole-number float literals
+    let _: f32 = 16_777_217.0;
+    let _: f32 = 16_777_219.0;
+    let _: f32 = 16_777_219.;
+    let _: f32 = 16_777_219.000;
+    let _ = 16_777_219f32;
+    let _: f32 = -16_777_219.0;
+    let _: f64 = 9_007_199_254_740_993.0;
+    let _: f64 = 9_007_199_254_740_993.;
+    let _: f64 = 9_007_199_254_740_993.000;
+    let _ = 9_007_199_254_740_993f64;
+    let _: f64 = -9_007_199_254_740_993.0;
+
+    // Lossless whole number float literals
+    let _: f32 = 16_777_216.0;
+    let _: f32 = 16_777_218.0;
+    let _: f32 = 16_777_220.0;
+    let _: f32 = -16_777_216.0;
+    let _: f32 = -16_777_220.0;
+    let _: f64 = 9_007_199_254_740_992.0;
+    let _: f64 = -9_007_199_254_740_992.0;
 }
diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr
index 12f8a61b75c..8941bcfd86d 100644
--- a/tests/ui/excessive_precision.stderr
+++ b/tests/ui/excessive_precision.stderr
@@ -2,7 +2,7 @@ error: float has excessive precision
   --> $DIR/excessive_precision.rs:15:26
    |
 LL |     const BAD32_1: f32 = 0.123_456_789_f32;
-   |                          ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79`
+   |                          ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79_f32`
    |
    = note: `-D clippy::excessive-precision` implied by `-D warnings`
 
@@ -28,7 +28,7 @@ error: float has excessive precision
   --> $DIR/excessive_precision.rs:20:26
    |
 LL |     const BAD64_1: f64 = 0.123_456_789_012_345_67f64;
-   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
+   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66_f64`
 
 error: float has excessive precision
   --> $DIR/excessive_precision.rs:21:26
@@ -58,13 +58,13 @@ error: float has excessive precision
   --> $DIR/excessive_precision.rs:37:26
    |
 LL |     let bad32_suf: f32 = 1.123_456_789_f32;
-   |                          ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8`
+   |                          ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32`
 
 error: float has excessive precision
   --> $DIR/excessive_precision.rs:38:21
    |
 LL |     let bad32_inf = 1.123_456_789_f32;
-   |                     ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8`
+   |                     ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32`
 
 error: float has excessive precision
   --> $DIR/excessive_precision.rs:40:22
@@ -76,7 +76,7 @@ error: float has excessive precision
   --> $DIR/excessive_precision.rs:41:26
    |
 LL |     let bad64_suf: f64 = 0.123_456_789_012_345_67f64;
-   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
+   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66_f64`
 
 error: float has excessive precision
   --> $DIR/excessive_precision.rs:42:21
@@ -108,5 +108,71 @@ error: float has excessive precision
 LL |     let bad_bige32: f32 = 1.123_456_788_888E-10;
    |                           ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8E-10`
 
-error: aborting due to 18 previous errors
+error: literal cannot be represented as the underlying type without loss of precision
+  --> $DIR/excessive_precision.rs:65:18
+   |
+LL |     let _: f32 = 16_777_217.0;
+   |                  ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_216.0`
+
+error: literal cannot be represented as the underlying type without loss of precision
+  --> $DIR/excessive_precision.rs:66:18
+   |
+LL |     let _: f32 = 16_777_219.0;
+   |                  ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0`
+
+error: literal cannot be represented as the underlying type without loss of precision
+  --> $DIR/excessive_precision.rs:67:18
+   |
+LL |     let _: f32 = 16_777_219.;
+   |                  ^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0`
+
+error: literal cannot be represented as the underlying type without loss of precision
+  --> $DIR/excessive_precision.rs:68:18
+   |
+LL |     let _: f32 = 16_777_219.000;
+   |                  ^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0`
+
+error: literal cannot be represented as the underlying type without loss of precision
+  --> $DIR/excessive_precision.rs:69:13
+   |
+LL |     let _ = 16_777_219f32;
+   |             ^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0_f32`
+
+error: literal cannot be represented as the underlying type without loss of precision
+  --> $DIR/excessive_precision.rs:70:19
+   |
+LL |     let _: f32 = -16_777_219.0;
+   |                   ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0`
+
+error: literal cannot be represented as the underlying type without loss of precision
+  --> $DIR/excessive_precision.rs:71:18
+   |
+LL |     let _: f64 = 9_007_199_254_740_993.0;
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0`
+
+error: literal cannot be represented as the underlying type without loss of precision
+  --> $DIR/excessive_precision.rs:72:18
+   |
+LL |     let _: f64 = 9_007_199_254_740_993.;
+   |                  ^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0`
+
+error: literal cannot be represented as the underlying type without loss of precision
+  --> $DIR/excessive_precision.rs:73:18
+   |
+LL |     let _: f64 = 9_007_199_254_740_993.000;
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0`
+
+error: literal cannot be represented as the underlying type without loss of precision
+  --> $DIR/excessive_precision.rs:74:13
+   |
+LL |     let _ = 9_007_199_254_740_993f64;
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0_f64`
+
+error: literal cannot be represented as the underlying type without loss of precision
+  --> $DIR/excessive_precision.rs:75:19
+   |
+LL |     let _: f64 = -9_007_199_254_740_993.0;
+   |                   ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0`
+
+error: aborting due to 29 previous errors