about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-12 09:43:37 +0000
committerbors <bors@rust-lang.org>2021-10-12 09:43:37 +0000
commit175738677cd018d9e6078768b25d1e8a2ee4cdf8 (patch)
tree8ba4496c5f1d3790b675f797d22405cd195ec59c
parentf44a904a56b92415c189be16e8d628e6c1473935 (diff)
parent44db27127249cf30a4d7a2e6e62762762e38a3cb (diff)
downloadrust-175738677cd018d9e6078768b25d1e8a2ee4cdf8.tar.gz
rust-175738677cd018d9e6078768b25d1e8a2ee4cdf8.zip
Auto merge of #89770 - jkugelman:must-use-from-and-into, r=joshtriplett
Add #[must_use] to From::from and Into::into

Risk of churn: **High**
Magic 8-Ball says: **Outlook not so good**

I figured I'd put this out there. If we don't do it now maybe we save it for a rainy day.

Parent issue: #89692

r? `@joshtriplett`
-rw-r--r--tests/ui/cast_lossless_float.fixed22
-rw-r--r--tests/ui/cast_lossless_float.rs22
-rw-r--r--tests/ui/cast_lossless_float.stderr66
-rw-r--r--tests/ui/cast_lossless_integer.fixed38
-rw-r--r--tests/ui/cast_lossless_integer.rs38
-rw-r--r--tests/ui/cast_lossless_integer.stderr114
6 files changed, 150 insertions, 150 deletions
diff --git a/tests/ui/cast_lossless_float.fixed b/tests/ui/cast_lossless_float.fixed
index 709d58b596c..32a9c1c4ae1 100644
--- a/tests/ui/cast_lossless_float.fixed
+++ b/tests/ui/cast_lossless_float.fixed
@@ -6,24 +6,24 @@
 fn main() {
     // Test clippy::cast_lossless with casts to floating-point types
     let x0 = 1i8;
-    f32::from(x0);
-    f64::from(x0);
+    let _ = f32::from(x0);
+    let _ = f64::from(x0);
     let x1 = 1u8;
-    f32::from(x1);
-    f64::from(x1);
+    let _ = f32::from(x1);
+    let _ = f64::from(x1);
     let x2 = 1i16;
-    f32::from(x2);
-    f64::from(x2);
+    let _ = f32::from(x2);
+    let _ = f64::from(x2);
     let x3 = 1u16;
-    f32::from(x3);
-    f64::from(x3);
+    let _ = f32::from(x3);
+    let _ = f64::from(x3);
     let x4 = 1i32;
-    f64::from(x4);
+    let _ = f64::from(x4);
     let x5 = 1u32;
-    f64::from(x5);
+    let _ = f64::from(x5);
 
     // Test with casts from floating-point types
-    f64::from(1.0f32);
+    let _ = f64::from(1.0f32);
 }
 
 // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
diff --git a/tests/ui/cast_lossless_float.rs b/tests/ui/cast_lossless_float.rs
index eb0aab88642..6f5ddcfe09c 100644
--- a/tests/ui/cast_lossless_float.rs
+++ b/tests/ui/cast_lossless_float.rs
@@ -6,24 +6,24 @@
 fn main() {
     // Test clippy::cast_lossless with casts to floating-point types
     let x0 = 1i8;
-    x0 as f32;
-    x0 as f64;
+    let _ = x0 as f32;
+    let _ = x0 as f64;
     let x1 = 1u8;
-    x1 as f32;
-    x1 as f64;
+    let _ = x1 as f32;
+    let _ = x1 as f64;
     let x2 = 1i16;
-    x2 as f32;
-    x2 as f64;
+    let _ = x2 as f32;
+    let _ = x2 as f64;
     let x3 = 1u16;
-    x3 as f32;
-    x3 as f64;
+    let _ = x3 as f32;
+    let _ = x3 as f64;
     let x4 = 1i32;
-    x4 as f64;
+    let _ = x4 as f64;
     let x5 = 1u32;
-    x5 as f64;
+    let _ = x5 as f64;
 
     // Test with casts from floating-point types
-    1.0f32 as f64;
+    let _ = 1.0f32 as f64;
 }
 
 // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
diff --git a/tests/ui/cast_lossless_float.stderr b/tests/ui/cast_lossless_float.stderr
index 0ed09f3083c..8326d40be71 100644
--- a/tests/ui/cast_lossless_float.stderr
+++ b/tests/ui/cast_lossless_float.stderr
@@ -1,70 +1,70 @@
 error: casting `i8` to `f32` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_float.rs:9:5
+  --> $DIR/cast_lossless_float.rs:9:13
    |
-LL |     x0 as f32;
-   |     ^^^^^^^^^ help: try: `f32::from(x0)`
+LL |     let _ = x0 as f32;
+   |             ^^^^^^^^^ help: try: `f32::from(x0)`
    |
    = note: `-D clippy::cast-lossless` implied by `-D warnings`
 
 error: casting `i8` to `f64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_float.rs:10:5
+  --> $DIR/cast_lossless_float.rs:10:13
    |
-LL |     x0 as f64;
-   |     ^^^^^^^^^ help: try: `f64::from(x0)`
+LL |     let _ = x0 as f64;
+   |             ^^^^^^^^^ help: try: `f64::from(x0)`
 
 error: casting `u8` to `f32` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_float.rs:12:5
+  --> $DIR/cast_lossless_float.rs:12:13
    |
-LL |     x1 as f32;
-   |     ^^^^^^^^^ help: try: `f32::from(x1)`
+LL |     let _ = x1 as f32;
+   |             ^^^^^^^^^ help: try: `f32::from(x1)`
 
 error: casting `u8` to `f64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_float.rs:13:5
+  --> $DIR/cast_lossless_float.rs:13:13
    |
-LL |     x1 as f64;
-   |     ^^^^^^^^^ help: try: `f64::from(x1)`
+LL |     let _ = x1 as f64;
+   |             ^^^^^^^^^ help: try: `f64::from(x1)`
 
 error: casting `i16` to `f32` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_float.rs:15:5
+  --> $DIR/cast_lossless_float.rs:15:13
    |
-LL |     x2 as f32;
-   |     ^^^^^^^^^ help: try: `f32::from(x2)`
+LL |     let _ = x2 as f32;
+   |             ^^^^^^^^^ help: try: `f32::from(x2)`
 
 error: casting `i16` to `f64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_float.rs:16:5
+  --> $DIR/cast_lossless_float.rs:16:13
    |
-LL |     x2 as f64;
-   |     ^^^^^^^^^ help: try: `f64::from(x2)`
+LL |     let _ = x2 as f64;
+   |             ^^^^^^^^^ help: try: `f64::from(x2)`
 
 error: casting `u16` to `f32` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_float.rs:18:5
+  --> $DIR/cast_lossless_float.rs:18:13
    |
-LL |     x3 as f32;
-   |     ^^^^^^^^^ help: try: `f32::from(x3)`
+LL |     let _ = x3 as f32;
+   |             ^^^^^^^^^ help: try: `f32::from(x3)`
 
 error: casting `u16` to `f64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_float.rs:19:5
+  --> $DIR/cast_lossless_float.rs:19:13
    |
-LL |     x3 as f64;
-   |     ^^^^^^^^^ help: try: `f64::from(x3)`
+LL |     let _ = x3 as f64;
+   |             ^^^^^^^^^ help: try: `f64::from(x3)`
 
 error: casting `i32` to `f64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_float.rs:21:5
+  --> $DIR/cast_lossless_float.rs:21:13
    |
-LL |     x4 as f64;
-   |     ^^^^^^^^^ help: try: `f64::from(x4)`
+LL |     let _ = x4 as f64;
+   |             ^^^^^^^^^ help: try: `f64::from(x4)`
 
 error: casting `u32` to `f64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_float.rs:23:5
+  --> $DIR/cast_lossless_float.rs:23:13
    |
-LL |     x5 as f64;
-   |     ^^^^^^^^^ help: try: `f64::from(x5)`
+LL |     let _ = x5 as f64;
+   |             ^^^^^^^^^ help: try: `f64::from(x5)`
 
 error: casting `f32` to `f64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_float.rs:26:5
+  --> $DIR/cast_lossless_float.rs:26:13
    |
-LL |     1.0f32 as f64;
-   |     ^^^^^^^^^^^^^ help: try: `f64::from(1.0f32)`
+LL |     let _ = 1.0f32 as f64;
+   |             ^^^^^^^^^^^^^ help: try: `f64::from(1.0f32)`
 
 error: aborting due to 11 previous errors
 
diff --git a/tests/ui/cast_lossless_integer.fixed b/tests/ui/cast_lossless_integer.fixed
index 03e49adb117..72a708b4073 100644
--- a/tests/ui/cast_lossless_integer.fixed
+++ b/tests/ui/cast_lossless_integer.fixed
@@ -5,27 +5,27 @@
 
 fn main() {
     // Test clippy::cast_lossless with casts to integer types
-    i16::from(1i8);
-    i32::from(1i8);
-    i64::from(1i8);
-    i16::from(1u8);
-    i32::from(1u8);
-    i64::from(1u8);
-    u16::from(1u8);
-    u32::from(1u8);
-    u64::from(1u8);
-    i32::from(1i16);
-    i64::from(1i16);
-    i32::from(1u16);
-    i64::from(1u16);
-    u32::from(1u16);
-    u64::from(1u16);
-    i64::from(1i32);
-    i64::from(1u32);
-    u64::from(1u32);
+    let _ = i16::from(1i8);
+    let _ = i32::from(1i8);
+    let _ = i64::from(1i8);
+    let _ = i16::from(1u8);
+    let _ = i32::from(1u8);
+    let _ = i64::from(1u8);
+    let _ = u16::from(1u8);
+    let _ = u32::from(1u8);
+    let _ = u64::from(1u8);
+    let _ = i32::from(1i16);
+    let _ = i64::from(1i16);
+    let _ = i32::from(1u16);
+    let _ = i64::from(1u16);
+    let _ = u32::from(1u16);
+    let _ = u64::from(1u16);
+    let _ = i64::from(1i32);
+    let _ = i64::from(1u32);
+    let _ = u64::from(1u32);
 
     // Test with an expression wrapped in parens
-    u16::from(1u8 + 1u8);
+    let _ = u16::from(1u8 + 1u8);
 }
 
 // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
diff --git a/tests/ui/cast_lossless_integer.rs b/tests/ui/cast_lossless_integer.rs
index 6a984d24596..34bb47181e6 100644
--- a/tests/ui/cast_lossless_integer.rs
+++ b/tests/ui/cast_lossless_integer.rs
@@ -5,27 +5,27 @@
 
 fn main() {
     // Test clippy::cast_lossless with casts to integer types
-    1i8 as i16;
-    1i8 as i32;
-    1i8 as i64;
-    1u8 as i16;
-    1u8 as i32;
-    1u8 as i64;
-    1u8 as u16;
-    1u8 as u32;
-    1u8 as u64;
-    1i16 as i32;
-    1i16 as i64;
-    1u16 as i32;
-    1u16 as i64;
-    1u16 as u32;
-    1u16 as u64;
-    1i32 as i64;
-    1u32 as i64;
-    1u32 as u64;
+    let _ = 1i8 as i16;
+    let _ = 1i8 as i32;
+    let _ = 1i8 as i64;
+    let _ = 1u8 as i16;
+    let _ = 1u8 as i32;
+    let _ = 1u8 as i64;
+    let _ = 1u8 as u16;
+    let _ = 1u8 as u32;
+    let _ = 1u8 as u64;
+    let _ = 1i16 as i32;
+    let _ = 1i16 as i64;
+    let _ = 1u16 as i32;
+    let _ = 1u16 as i64;
+    let _ = 1u16 as u32;
+    let _ = 1u16 as u64;
+    let _ = 1i32 as i64;
+    let _ = 1u32 as i64;
+    let _ = 1u32 as u64;
 
     // Test with an expression wrapped in parens
-    (1u8 + 1u8) as u16;
+    let _ = (1u8 + 1u8) as u16;
 }
 
 // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
diff --git a/tests/ui/cast_lossless_integer.stderr b/tests/ui/cast_lossless_integer.stderr
index 8e2890f9c28..721b94876cb 100644
--- a/tests/ui/cast_lossless_integer.stderr
+++ b/tests/ui/cast_lossless_integer.stderr
@@ -1,118 +1,118 @@
 error: casting `i8` to `i16` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:8:5
+  --> $DIR/cast_lossless_integer.rs:8:13
    |
-LL |     1i8 as i16;
-   |     ^^^^^^^^^^ help: try: `i16::from(1i8)`
+LL |     let _ = 1i8 as i16;
+   |             ^^^^^^^^^^ help: try: `i16::from(1i8)`
    |
    = note: `-D clippy::cast-lossless` implied by `-D warnings`
 
 error: casting `i8` to `i32` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:9:5
+  --> $DIR/cast_lossless_integer.rs:9:13
    |
-LL |     1i8 as i32;
-   |     ^^^^^^^^^^ help: try: `i32::from(1i8)`
+LL |     let _ = 1i8 as i32;
+   |             ^^^^^^^^^^ help: try: `i32::from(1i8)`
 
 error: casting `i8` to `i64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:10:5
+  --> $DIR/cast_lossless_integer.rs:10:13
    |
-LL |     1i8 as i64;
-   |     ^^^^^^^^^^ help: try: `i64::from(1i8)`
+LL |     let _ = 1i8 as i64;
+   |             ^^^^^^^^^^ help: try: `i64::from(1i8)`
 
 error: casting `u8` to `i16` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:11:5
+  --> $DIR/cast_lossless_integer.rs:11:13
    |
-LL |     1u8 as i16;
-   |     ^^^^^^^^^^ help: try: `i16::from(1u8)`
+LL |     let _ = 1u8 as i16;
+   |             ^^^^^^^^^^ help: try: `i16::from(1u8)`
 
 error: casting `u8` to `i32` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:12:5
+  --> $DIR/cast_lossless_integer.rs:12:13
    |
-LL |     1u8 as i32;
-   |     ^^^^^^^^^^ help: try: `i32::from(1u8)`
+LL |     let _ = 1u8 as i32;
+   |             ^^^^^^^^^^ help: try: `i32::from(1u8)`
 
 error: casting `u8` to `i64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:13:5
+  --> $DIR/cast_lossless_integer.rs:13:13
    |
-LL |     1u8 as i64;
-   |     ^^^^^^^^^^ help: try: `i64::from(1u8)`
+LL |     let _ = 1u8 as i64;
+   |             ^^^^^^^^^^ help: try: `i64::from(1u8)`
 
 error: casting `u8` to `u16` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:14:5
+  --> $DIR/cast_lossless_integer.rs:14:13
    |
-LL |     1u8 as u16;
-   |     ^^^^^^^^^^ help: try: `u16::from(1u8)`
+LL |     let _ = 1u8 as u16;
+   |             ^^^^^^^^^^ help: try: `u16::from(1u8)`
 
 error: casting `u8` to `u32` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:15:5
+  --> $DIR/cast_lossless_integer.rs:15:13
    |
-LL |     1u8 as u32;
-   |     ^^^^^^^^^^ help: try: `u32::from(1u8)`
+LL |     let _ = 1u8 as u32;
+   |             ^^^^^^^^^^ help: try: `u32::from(1u8)`
 
 error: casting `u8` to `u64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:16:5
+  --> $DIR/cast_lossless_integer.rs:16:13
    |
-LL |     1u8 as u64;
-   |     ^^^^^^^^^^ help: try: `u64::from(1u8)`
+LL |     let _ = 1u8 as u64;
+   |             ^^^^^^^^^^ help: try: `u64::from(1u8)`
 
 error: casting `i16` to `i32` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:17:5
+  --> $DIR/cast_lossless_integer.rs:17:13
    |
-LL |     1i16 as i32;
-   |     ^^^^^^^^^^^ help: try: `i32::from(1i16)`
+LL |     let _ = 1i16 as i32;
+   |             ^^^^^^^^^^^ help: try: `i32::from(1i16)`
 
 error: casting `i16` to `i64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:18:5
+  --> $DIR/cast_lossless_integer.rs:18:13
    |
-LL |     1i16 as i64;
-   |     ^^^^^^^^^^^ help: try: `i64::from(1i16)`
+LL |     let _ = 1i16 as i64;
+   |             ^^^^^^^^^^^ help: try: `i64::from(1i16)`
 
 error: casting `u16` to `i32` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:19:5
+  --> $DIR/cast_lossless_integer.rs:19:13
    |
-LL |     1u16 as i32;
-   |     ^^^^^^^^^^^ help: try: `i32::from(1u16)`
+LL |     let _ = 1u16 as i32;
+   |             ^^^^^^^^^^^ help: try: `i32::from(1u16)`
 
 error: casting `u16` to `i64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:20:5
+  --> $DIR/cast_lossless_integer.rs:20:13
    |
-LL |     1u16 as i64;
-   |     ^^^^^^^^^^^ help: try: `i64::from(1u16)`
+LL |     let _ = 1u16 as i64;
+   |             ^^^^^^^^^^^ help: try: `i64::from(1u16)`
 
 error: casting `u16` to `u32` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:21:5
+  --> $DIR/cast_lossless_integer.rs:21:13
    |
-LL |     1u16 as u32;
-   |     ^^^^^^^^^^^ help: try: `u32::from(1u16)`
+LL |     let _ = 1u16 as u32;
+   |             ^^^^^^^^^^^ help: try: `u32::from(1u16)`
 
 error: casting `u16` to `u64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:22:5
+  --> $DIR/cast_lossless_integer.rs:22:13
    |
-LL |     1u16 as u64;
-   |     ^^^^^^^^^^^ help: try: `u64::from(1u16)`
+LL |     let _ = 1u16 as u64;
+   |             ^^^^^^^^^^^ help: try: `u64::from(1u16)`
 
 error: casting `i32` to `i64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:23:5
+  --> $DIR/cast_lossless_integer.rs:23:13
    |
-LL |     1i32 as i64;
-   |     ^^^^^^^^^^^ help: try: `i64::from(1i32)`
+LL |     let _ = 1i32 as i64;
+   |             ^^^^^^^^^^^ help: try: `i64::from(1i32)`
 
 error: casting `u32` to `i64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:24:5
+  --> $DIR/cast_lossless_integer.rs:24:13
    |
-LL |     1u32 as i64;
-   |     ^^^^^^^^^^^ help: try: `i64::from(1u32)`
+LL |     let _ = 1u32 as i64;
+   |             ^^^^^^^^^^^ help: try: `i64::from(1u32)`
 
 error: casting `u32` to `u64` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:25:5
+  --> $DIR/cast_lossless_integer.rs:25:13
    |
-LL |     1u32 as u64;
-   |     ^^^^^^^^^^^ help: try: `u64::from(1u32)`
+LL |     let _ = 1u32 as u64;
+   |             ^^^^^^^^^^^ help: try: `u64::from(1u32)`
 
 error: casting `u8` to `u16` may become silently lossy if you later change the type
-  --> $DIR/cast_lossless_integer.rs:28:5
+  --> $DIR/cast_lossless_integer.rs:28:13
    |
-LL |     (1u8 + 1u8) as u16;
-   |     ^^^^^^^^^^^^^^^^^^ help: try: `u16::from(1u8 + 1u8)`
+LL |     let _ = (1u8 + 1u8) as u16;
+   |             ^^^^^^^^^^^^^^^^^^ help: try: `u16::from(1u8 + 1u8)`
 
 error: aborting due to 19 previous errors