about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCameron Steffen <cam.steffen94@gmail.com>2020-11-29 18:21:21 -0600
committerCameron Steffen <cam.steffen94@gmail.com>2020-11-29 18:21:21 -0600
commit0e207888391fb8b55fa75d19259812b6cb97a75c (patch)
tree48503c408109f26a0529dd027704875ff6164b2f
parenta5d6855333c55636bc0fc56efcc83eac7c57ffa7 (diff)
downloadrust-0e207888391fb8b55fa75d19259812b6cb97a75c.tar.gz
rust-0e207888391fb8b55fa75d19259812b6cb97a75c.zip
Split tests
-rw-r--r--tests/ui/collapsible_match.rs39
-rw-r--r--tests/ui/collapsible_match.stderr60
-rw-r--r--tests/ui/collapsible_match2.rs53
-rw-r--r--tests/ui/collapsible_match2.stderr61
4 files changed, 115 insertions, 98 deletions
diff --git a/tests/ui/collapsible_match.rs b/tests/ui/collapsible_match.rs
index 75640b70ff0..a83e6c77b12 100644
--- a/tests/ui/collapsible_match.rs
+++ b/tests/ui/collapsible_match.rs
@@ -95,45 +95,6 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
         },
         None => return,
     }
-
-    // if guards on outer match
-    {
-        match res_opt {
-            Ok(val) if make() => match val {
-                Some(n) => foo(n),
-                _ => return,
-            },
-            _ => return,
-        }
-        match res_opt {
-            Ok(val) => match val {
-                Some(n) => foo(n),
-                _ => return,
-            },
-            _ if make() => return,
-            _ => return,
-        }
-    }
-
-    // macro
-    {
-        macro_rules! mac {
-            ($outer:expr => $pat:pat, $e:expr => $inner_pat:pat, $then:expr) => {
-                match $outer {
-                    $pat => match $e {
-                        $inner_pat => $then,
-                        _ => return,
-                    },
-                    _ => return,
-                }
-            };
-        }
-        // Lint this since the patterns are not defined by the macro.
-        // Allows the lint to work on if_chain! for example.
-        // Fixing the lint requires knowledge of the specific macro, but we optimistically assume that
-        // there is still a better way to write this.
-        mac!(res_opt => Ok(val), val => Some(n), foo(n));
-    }
 }
 
 fn negative_cases(res_opt: Result<Option<u32>, String>, res_res: Result<Result<u32, String>, String>) {
diff --git a/tests/ui/collapsible_match.stderr b/tests/ui/collapsible_match.stderr
index a9e4f911914..63ac6a1613d 100644
--- a/tests/ui/collapsible_match.stderr
+++ b/tests/ui/collapsible_match.stderr
@@ -175,63 +175,5 @@ LL |         Some(val) => match val {
 LL |             Some(n) => foo(n),
    |             ^^^^^^^ with this pattern
 
-error: Unnecessary nested match
-  --> $DIR/collapsible_match.rs:102:34
-   |
-LL |               Ok(val) if make() => match val {
-   |  __________________________________^
-LL | |                 Some(n) => foo(n),
-LL | |                 _ => return,
-LL | |             },
-   | |_____________^
-   |
-help: The outer pattern can be modified to include the inner pattern.
-  --> $DIR/collapsible_match.rs:102:16
-   |
-LL |             Ok(val) if make() => match val {
-   |                ^^^ Replace this binding
-LL |                 Some(n) => foo(n),
-   |                 ^^^^^^^ with this pattern
-
-error: Unnecessary nested match
-  --> $DIR/collapsible_match.rs:109:24
-   |
-LL |               Ok(val) => match val {
-   |  ________________________^
-LL | |                 Some(n) => foo(n),
-LL | |                 _ => return,
-LL | |             },
-   | |_____________^
-   |
-help: The outer pattern can be modified to include the inner pattern.
-  --> $DIR/collapsible_match.rs:109:16
-   |
-LL |             Ok(val) => match val {
-   |                ^^^ Replace this binding
-LL |                 Some(n) => foo(n),
-   |                 ^^^^^^^ with this pattern
-
-error: Unnecessary nested match
-  --> $DIR/collapsible_match.rs:123:29
-   |
-LL |                       $pat => match $e {
-   |  _____________________________^
-LL | |                         $inner_pat => $then,
-LL | |                         _ => return,
-LL | |                     },
-   | |_____________________^
-...
-LL |           mac!(res_opt => Ok(val), val => Some(n), foo(n));
-   |           ------------------------------------------------- in this macro invocation
-   |
-help: The outer pattern can be modified to include the inner pattern.
-  --> $DIR/collapsible_match.rs:135:28
-   |
-LL |         mac!(res_opt => Ok(val), val => Some(n), foo(n));
-   |                            ^^^          ^^^^^^^ with this pattern
-   |                            |
-   |                            Replace this binding
-   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: aborting due to 13 previous errors
+error: aborting due to 10 previous errors
 
diff --git a/tests/ui/collapsible_match2.rs b/tests/ui/collapsible_match2.rs
new file mode 100644
index 00000000000..d571ac4ab69
--- /dev/null
+++ b/tests/ui/collapsible_match2.rs
@@ -0,0 +1,53 @@
+#![warn(clippy::collapsible_match)]
+#![allow(clippy::needless_return, clippy::no_effect, clippy::single_match)]
+
+fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>) {
+    // if guards on outer match
+    {
+        match res_opt {
+            Ok(val) if make() => match val {
+                Some(n) => foo(n),
+                _ => return,
+            },
+            _ => return,
+        }
+        match res_opt {
+            Ok(val) => match val {
+                Some(n) => foo(n),
+                _ => return,
+            },
+            _ if make() => return,
+            _ => return,
+        }
+    }
+
+    // macro
+    {
+        macro_rules! mac {
+            ($outer:expr => $pat:pat, $e:expr => $inner_pat:pat, $then:expr) => {
+                match $outer {
+                    $pat => match $e {
+                        $inner_pat => $then,
+                        _ => return,
+                    },
+                    _ => return,
+                }
+            };
+        }
+        // Lint this since the patterns are not defined by the macro.
+        // Allows the lint to work on if_chain! for example.
+        // Fixing the lint requires knowledge of the specific macro, but we optimistically assume that
+        // there is still a better way to write this.
+        mac!(res_opt => Ok(val), val => Some(n), foo(n));
+    }
+}
+
+fn make<T>() -> T {
+    unimplemented!()
+}
+
+fn foo<T, U>(t: T) -> U {
+    unimplemented!()
+}
+
+fn main() {}
diff --git a/tests/ui/collapsible_match2.stderr b/tests/ui/collapsible_match2.stderr
new file mode 100644
index 00000000000..490d82d12cd
--- /dev/null
+++ b/tests/ui/collapsible_match2.stderr
@@ -0,0 +1,61 @@
+error: Unnecessary nested match
+  --> $DIR/collapsible_match2.rs:8:34
+   |
+LL |               Ok(val) if make() => match val {
+   |  __________________________________^
+LL | |                 Some(n) => foo(n),
+LL | |                 _ => return,
+LL | |             },
+   | |_____________^
+   |
+   = note: `-D clippy::collapsible-match` implied by `-D warnings`
+help: The outer pattern can be modified to include the inner pattern.
+  --> $DIR/collapsible_match2.rs:8:16
+   |
+LL |             Ok(val) if make() => match val {
+   |                ^^^ Replace this binding
+LL |                 Some(n) => foo(n),
+   |                 ^^^^^^^ with this pattern
+
+error: Unnecessary nested match
+  --> $DIR/collapsible_match2.rs:15:24
+   |
+LL |               Ok(val) => match val {
+   |  ________________________^
+LL | |                 Some(n) => foo(n),
+LL | |                 _ => return,
+LL | |             },
+   | |_____________^
+   |
+help: The outer pattern can be modified to include the inner pattern.
+  --> $DIR/collapsible_match2.rs:15:16
+   |
+LL |             Ok(val) => match val {
+   |                ^^^ Replace this binding
+LL |                 Some(n) => foo(n),
+   |                 ^^^^^^^ with this pattern
+
+error: Unnecessary nested match
+  --> $DIR/collapsible_match2.rs:29:29
+   |
+LL |                       $pat => match $e {
+   |  _____________________________^
+LL | |                         $inner_pat => $then,
+LL | |                         _ => return,
+LL | |                     },
+   | |_____________________^
+...
+LL |           mac!(res_opt => Ok(val), val => Some(n), foo(n));
+   |           ------------------------------------------------- in this macro invocation
+   |
+help: The outer pattern can be modified to include the inner pattern.
+  --> $DIR/collapsible_match2.rs:41:28
+   |
+LL |         mac!(res_opt => Ok(val), val => Some(n), foo(n));
+   |                            ^^^          ^^^^^^^ with this pattern
+   |                            |
+   |                            Replace this binding
+   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 3 previous errors
+