]> git.lizzy.rs Git - rust.git/commitdiff
Split up cast.rs tests, run-rustfix for unnecessary_cast
authorPhilipp Hansch <dev@phansch.net>
Sun, 4 Aug 2019 06:24:23 +0000 (08:24 +0200)
committerPhilipp Hansch <dev@phansch.net>
Sun, 4 Aug 2019 06:24:23 +0000 (08:24 +0200)
This splits up the cast.rs tests and enables rustfix tests for the part
of the `unnecessary_cast` lint that emits `MachineApplicable`
suggestions.

cc #3630

tests/ui/cast.rs
tests/ui/cast.stderr
tests/ui/unnecessary_cast.rs [new file with mode: 0644]
tests/ui/unnecessary_cast.stderr [new file with mode: 0644]
tests/ui/unnecessary_cast_fixable.fixed [new file with mode: 0644]
tests/ui/unnecessary_cast_fixable.rs [new file with mode: 0644]
tests/ui/unnecessary_cast_fixable.stderr [new file with mode: 0644]

index 16da099bd2115c3c7aac81bc6c46a6f01ae41b0a..79705071999249b6570967f82de4281633d41172 100644 (file)
@@ -42,32 +42,4 @@ fn main() {
     i32::max_value() as u32;
     i64::max_value() as u64;
     i128::max_value() as u128;
-    // Extra checks for *size
-    // Test cast_unnecessary
-    1i32 as i32;
-    1f32 as f32;
-    false as bool;
-    &1i32 as &i32;
-    // macro version
-    macro_rules! foo {
-        ($a:ident, $b:ident) => {
-            pub fn $a() -> $b {
-                1 as $b
-            }
-        };
-    }
-    foo!(a, i32);
-    foo!(b, f32);
-    foo!(c, f64);
-
-    // casting integer literal to float is unnecessary
-    100 as f32;
-    100 as f64;
-    100_i32 as f64;
-    // Should not trigger
-    #[rustfmt::skip]
-    let v = vec!(1);
-    &v as &[i32];
-    1.0 as f64;
-    1 as u64;
 }
index 42232808c9bc549130e96dc259b41f789466e21a..0ebd3a1f184dcade930e41e73263903dc2e64ace 100644 (file)
@@ -138,43 +138,5 @@ error: casting isize to usize may lose the sign of the value
 LL |     -1isize as usize;
    |     ^^^^^^^^^^^^^^^^
 
-error: casting to the same type is unnecessary (`i32` -> `i32`)
-  --> $DIR/cast.rs:47:5
-   |
-LL |     1i32 as i32;
-   |     ^^^^^^^^^^^
-   |
-   = note: `-D clippy::unnecessary-cast` implied by `-D warnings`
-
-error: casting to the same type is unnecessary (`f32` -> `f32`)
-  --> $DIR/cast.rs:48:5
-   |
-LL |     1f32 as f32;
-   |     ^^^^^^^^^^^
-
-error: casting to the same type is unnecessary (`bool` -> `bool`)
-  --> $DIR/cast.rs:49:5
-   |
-LL |     false as bool;
-   |     ^^^^^^^^^^^^^
-
-error: casting integer literal to f32 is unnecessary
-  --> $DIR/cast.rs:64:5
-   |
-LL |     100 as f32;
-   |     ^^^^^^^^^^ help: try: `100_f32`
-
-error: casting integer literal to f64 is unnecessary
-  --> $DIR/cast.rs:65:5
-   |
-LL |     100 as f64;
-   |     ^^^^^^^^^^ help: try: `100_f64`
-
-error: casting integer literal to f64 is unnecessary
-  --> $DIR/cast.rs:66:5
-   |
-LL |     100_i32 as f64;
-   |     ^^^^^^^^^^^^^^ help: try: `100_f64`
-
-error: aborting due to 28 previous errors
+error: aborting due to 22 previous errors
 
diff --git a/tests/ui/unnecessary_cast.rs b/tests/ui/unnecessary_cast.rs
new file mode 100644 (file)
index 0000000..df9b227
--- /dev/null
@@ -0,0 +1,23 @@
+#![warn(clippy::unnecessary_cast)]
+#![allow(clippy::no_effect)]
+
+fn main() {
+    // Test cast_unnecessary
+    1i32 as i32;
+    1f32 as f32;
+    false as bool;
+    &1i32 as &i32;
+
+    // macro version
+    macro_rules! foo {
+        ($a:ident, $b:ident) => {
+            #[allow(unused)]
+            pub fn $a() -> $b {
+                1 as $b
+            }
+        };
+    }
+    foo!(a, i32);
+    foo!(b, f32);
+    foo!(c, f64);
+}
diff --git a/tests/ui/unnecessary_cast.stderr b/tests/ui/unnecessary_cast.stderr
new file mode 100644 (file)
index 0000000..8981d13
--- /dev/null
@@ -0,0 +1,22 @@
+error: casting to the same type is unnecessary (`i32` -> `i32`)
+  --> $DIR/unnecessary_cast.rs:6:5
+   |
+LL |     1i32 as i32;
+   |     ^^^^^^^^^^^
+   |
+   = note: `-D clippy::unnecessary-cast` implied by `-D warnings`
+
+error: casting to the same type is unnecessary (`f32` -> `f32`)
+  --> $DIR/unnecessary_cast.rs:7:5
+   |
+LL |     1f32 as f32;
+   |     ^^^^^^^^^^^
+
+error: casting to the same type is unnecessary (`bool` -> `bool`)
+  --> $DIR/unnecessary_cast.rs:8:5
+   |
+LL |     false as bool;
+   |     ^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors
+
diff --git a/tests/ui/unnecessary_cast_fixable.fixed b/tests/ui/unnecessary_cast_fixable.fixed
new file mode 100644 (file)
index 0000000..8c659df
--- /dev/null
@@ -0,0 +1,17 @@
+// run-rustfix
+
+#![warn(clippy::unnecessary_cast)]
+#![allow(clippy::no_effect, clippy::unnecessary_operation)]
+
+fn main() {
+    // casting integer literal to float is unnecessary
+    100_f32;
+    100_f64;
+    100_f64;
+    // Should not trigger
+    #[rustfmt::skip]
+    let v = vec!(1);
+    &v as &[i32];
+    1.0 as f64;
+    1 as u64;
+}
diff --git a/tests/ui/unnecessary_cast_fixable.rs b/tests/ui/unnecessary_cast_fixable.rs
new file mode 100644 (file)
index 0000000..7bab554
--- /dev/null
@@ -0,0 +1,17 @@
+// run-rustfix
+
+#![warn(clippy::unnecessary_cast)]
+#![allow(clippy::no_effect, clippy::unnecessary_operation)]
+
+fn main() {
+    // casting integer literal to float is unnecessary
+    100 as f32;
+    100 as f64;
+    100_i32 as f64;
+    // Should not trigger
+    #[rustfmt::skip]
+    let v = vec!(1);
+    &v as &[i32];
+    1.0 as f64;
+    1 as u64;
+}
diff --git a/tests/ui/unnecessary_cast_fixable.stderr b/tests/ui/unnecessary_cast_fixable.stderr
new file mode 100644 (file)
index 0000000..74616bb
--- /dev/null
@@ -0,0 +1,22 @@
+error: casting integer literal to f32 is unnecessary
+  --> $DIR/unnecessary_cast_fixable.rs:8:5
+   |
+LL |     100 as f32;
+   |     ^^^^^^^^^^ help: try: `100_f32`
+   |
+   = note: `-D clippy::unnecessary-cast` implied by `-D warnings`
+
+error: casting integer literal to f64 is unnecessary
+  --> $DIR/unnecessary_cast_fixable.rs:9:5
+   |
+LL |     100 as f64;
+   |     ^^^^^^^^^^ help: try: `100_f64`
+
+error: casting integer literal to f64 is unnecessary
+  --> $DIR/unnecessary_cast_fixable.rs:10:5
+   |
+LL |     100_i32 as f64;
+   |     ^^^^^^^^^^^^^^ help: try: `100_f64`
+
+error: aborting due to 3 previous errors
+