about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilco Kusee <wilcokusee@gmail.com>2019-01-13 12:49:54 +0100
committerWilco Kusee <wilcokusee@gmail.com>2019-01-13 12:49:54 +0100
commit787f5a2c12e72af923c1b0983e0f5b97839bcd40 (patch)
tree51d0522bbbd6a4c7c49e72db480f5d674579b1ed
parent87407c5e5f27ade439ddf5b98e5d739ddb4ef1bd (diff)
downloadrust-787f5a2c12e72af923c1b0983e0f5b97839bcd40.tar.gz
rust-787f5a2c12e72af923c1b0983e0f5b97839bcd40.zip
Add run-rustfix to infallible_destructuring_match
-rw-r--r--tests/ui/infallible_destructuring_match.fixed79
-rw-r--r--tests/ui/infallible_destructuring_match.rs2
-rw-r--r--tests/ui/infallible_destructuring_match.stderr6
3 files changed, 84 insertions, 3 deletions
diff --git a/tests/ui/infallible_destructuring_match.fixed b/tests/ui/infallible_destructuring_match.fixed
new file mode 100644
index 00000000000..f16f0fd0019
--- /dev/null
+++ b/tests/ui/infallible_destructuring_match.fixed
@@ -0,0 +1,79 @@
+// run-rustfix
+#![feature(exhaustive_patterns, never_type)]
+#![allow(dead_code, unreachable_code, unused_variables)]
+#![allow(clippy::let_and_return)]
+
+enum SingleVariantEnum {
+    Variant(i32),
+}
+
+struct TupleStruct(i32);
+
+enum EmptyEnum {}
+
+fn infallible_destructuring_match_enum() {
+    let wrapper = SingleVariantEnum::Variant(0);
+
+    // This should lint!
+    let SingleVariantEnum::Variant(data) = wrapper;
+
+    // This shouldn't!
+    let data = match wrapper {
+        SingleVariantEnum::Variant(_) => -1,
+    };
+
+    // Neither should this!
+    let data = match wrapper {
+        SingleVariantEnum::Variant(i) => -1,
+    };
+
+    let SingleVariantEnum::Variant(data) = wrapper;
+}
+
+fn infallible_destructuring_match_struct() {
+    let wrapper = TupleStruct(0);
+
+    // This should lint!
+    let TupleStruct(data) = wrapper;
+
+    // This shouldn't!
+    let data = match wrapper {
+        TupleStruct(_) => -1,
+    };
+
+    // Neither should this!
+    let data = match wrapper {
+        TupleStruct(i) => -1,
+    };
+
+    let TupleStruct(data) = wrapper;
+}
+
+fn never_enum() {
+    let wrapper: Result<i32, !> = Ok(23);
+
+    // This should lint!
+    let Ok(data) = wrapper;
+
+    // This shouldn't!
+    let data = match wrapper {
+        Ok(_) => -1,
+    };
+
+    // Neither should this!
+    let data = match wrapper {
+        Ok(i) => -1,
+    };
+
+    let Ok(data) = wrapper;
+}
+
+impl EmptyEnum {
+    fn match_on(&self) -> ! {
+        // The lint shouldn't pick this up, as `let` won't work here!
+        let data = match *self {};
+        data
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/infallible_destructuring_match.rs b/tests/ui/infallible_destructuring_match.rs
index a34b06d5642..a4823ad60ad 100644
--- a/tests/ui/infallible_destructuring_match.rs
+++ b/tests/ui/infallible_destructuring_match.rs
@@ -1,4 +1,6 @@
+// run-rustfix
 #![feature(exhaustive_patterns, never_type)]
+#![allow(dead_code, unreachable_code, unused_variables)]
 #![allow(clippy::let_and_return)]
 
 enum SingleVariantEnum {
diff --git a/tests/ui/infallible_destructuring_match.stderr b/tests/ui/infallible_destructuring_match.stderr
index b2b37b9bff7..e3693d44e9a 100644
--- a/tests/ui/infallible_destructuring_match.stderr
+++ b/tests/ui/infallible_destructuring_match.stderr
@@ -1,5 +1,5 @@
 error: you seem to be trying to use match to destructure a single infallible pattern. Consider using `let`
-  --> $DIR/infallible_destructuring_match.rs:16:5
+  --> $DIR/infallible_destructuring_match.rs:18:5
    |
 LL | /     let data = match wrapper {
 LL | |         SingleVariantEnum::Variant(i) => i,
@@ -9,7 +9,7 @@ LL | |     };
    = note: `-D clippy::infallible-destructuring-match` implied by `-D warnings`
 
 error: you seem to be trying to use match to destructure a single infallible pattern. Consider using `let`
-  --> $DIR/infallible_destructuring_match.rs:37:5
+  --> $DIR/infallible_destructuring_match.rs:39:5
    |
 LL | /     let data = match wrapper {
 LL | |         TupleStruct(i) => i,
@@ -17,7 +17,7 @@ LL | |     };
    | |______^ help: try this: `let TupleStruct(data) = wrapper;`
 
 error: you seem to be trying to use match to destructure a single infallible pattern. Consider using `let`
-  --> $DIR/infallible_destructuring_match.rs:58:5
+  --> $DIR/infallible_destructuring_match.rs:60:5
    |
 LL | /     let data = match wrapper {
 LL | |         Ok(i) => i,