about summary refs log tree commit diff
diff options
context:
space:
mode:
authordswij <dswijj@gmail.com>2021-08-14 16:59:08 +0800
committerdswij <dswijj@gmail.com>2021-08-16 16:24:44 +0800
commit711c5cb6d2bd88dffff5c4da378d5796095c0cd2 (patch)
tree3635d42e305d47fff35443318dac6e4d268c7e25
parent3f0c97740f10372a6dc8a085eba571822911afc7 (diff)
downloadrust-711c5cb6d2bd88dffff5c4da378d5796095c0cd2.tar.gz
rust-711c5cb6d2bd88dffff5c4da378d5796095c0cd2.zip
Add false positive test for `manual_flatten`
Add a scenario where `manual_flatten` is triggered when match expression will still be used after the match in `if let`.
-rw-r--r--tests/ui/manual_flatten.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/ui/manual_flatten.rs b/tests/ui/manual_flatten.rs
index b5bd35a6878..7db6b730963 100644
--- a/tests/ui/manual_flatten.rs
+++ b/tests/ui/manual_flatten.rs
@@ -91,6 +91,19 @@ fn main() {
         }
     }
 
+    struct Test {
+        a: usize,
+    }
+
+    let mut vec_of_struct = [Some(Test { a: 1 }), None];
+
+    // Usage of `if let` expression should not trigger lint
+    for n in vec_of_struct.iter_mut() {
+        if let Some(z) = n {
+            *n = None;
+        }
+    }
+
     // Using manual flatten should not trigger the lint
     for n in vec![Some(1), Some(2), Some(3)].iter().flatten() {
         println!("{}", n);