]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/collapsible_match.rs
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / collapsible_match.rs
index 75640b70ff06e8a98c903a9d3bec0eeb3c607dfe..1d7a72846419f48bc3c60990672dc3471a52886b 100644 (file)
@@ -1,5 +1,11 @@
 #![warn(clippy::collapsible_match)]
-#![allow(clippy::needless_return, clippy::no_effect, clippy::single_match)]
+#![allow(
+    clippy::equatable_if_let,
+    clippy::needless_return,
+    clippy::no_effect,
+    clippy::single_match,
+    clippy::uninlined_format_args
+)]
 
 fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>) {
     // match without block
@@ -95,48 +101,14 @@ 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>) {
+    while let Some(x) = make() {
+        if let Some(1) = x {
+            todo!();
+        }
+    }
     // no wild pattern in outer match
     match res_opt {
         Ok(val) => match val {
@@ -263,6 +235,43 @@ enum E<T> {
         },
         _ => return,
     }
+    if let Ok(val) = res_opt {
+        if let Some(n) = val {
+            let _ = || {
+                // usage in closure
+                println!("{:?}", val);
+            };
+        }
+    }
+    let _: &dyn std::any::Any = match &Some(Some(1)) {
+        Some(e) => match e {
+            Some(e) => e,
+            e => e,
+        },
+        // else branch looks the same but the binding is different
+        e => e,
+    };
+}
+
+pub enum Issue9647 {
+    A { a: Option<Option<u8>>, b: () },
+    B,
+}
+
+pub fn test_1(x: Issue9647) {
+    if let Issue9647::A { a, .. } = x {
+        if let Some(u) = a {
+            println!("{u:?}")
+        }
+    }
+}
+
+pub fn test_2(x: Issue9647) {
+    if let Issue9647::A { a: Some(a), .. } = x {
+        if let Some(u) = a {
+            println!("{u}")
+        }
+    }
 }
 
 fn make<T>() -> T {