]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/manual_map_option.rs
Addition `manual_map` test for `unsafe` blocks
[rust.git] / tests / ui / manual_map_option.rs
index 8b8187db0a9798217c024cddf2e40f6b93a05112..d11bf5ecb825ae28a1ae76ba6f1594199e37dfc8 100644 (file)
@@ -1,7 +1,14 @@
 // run-rustfix
 
 #![warn(clippy::manual_map)]
-#![allow(clippy::no_effect, clippy::map_identity, clippy::unit_arg, clippy::match_ref_pats)]
+#![allow(
+    clippy::no_effect,
+    clippy::map_identity,
+    clippy::unit_arg,
+    clippy::match_ref_pats,
+    clippy::redundant_pattern_matching,
+    dead_code
+)]
 
 fn main() {
     match Some(0) {
@@ -119,4 +126,96 @@ fn main() {
         Some(Some((x, 1))) => Some(x),
         _ => None,
     };
+
+    // #6795
+    fn f1() -> Result<(), ()> {
+        let _ = match Some(Ok(())) {
+            Some(x) => Some(x?),
+            None => None,
+        };
+        Ok(())
+    }
+
+    for &x in Some(Some(true)).iter() {
+        let _ = match x {
+            Some(x) => Some(if x { continue } else { x }),
+            None => None,
+        };
+    }
+
+    // #6797
+    let x1 = (Some(String::new()), 0);
+    let x2 = x1.0;
+    match x2 {
+        Some(x) => Some((x, x1.1)),
+        None => None,
+    };
+
+    struct S1 {
+        x: Option<String>,
+        y: u32,
+    }
+    impl S1 {
+        fn f(self) -> Option<(String, u32)> {
+            match self.x {
+                Some(x) => Some((x, self.y)),
+                None => None,
+            }
+        }
+    }
+
+    // #6811
+    match Some(0) {
+        Some(x) => Some(vec![x]),
+        None => None,
+    };
+
+    match option_env!("") {
+        Some(x) => Some(String::from(x)),
+        None => None,
+    };
+
+    // #6819
+    async fn f2(x: u32) -> u32 {
+        x
+    }
+
+    async fn f3() {
+        match Some(0) {
+            Some(x) => Some(f2(x).await),
+            None => None,
+        };
+    }
+
+    // #6847
+    if let Some(_) = Some(0) {
+        Some(0)
+    } else if let Some(x) = Some(0) {
+        Some(x + 1)
+    } else {
+        None
+    };
+
+    if true {
+        Some(0)
+    } else if let Some(x) = Some(0) {
+        Some(x + 1)
+    } else {
+        None
+    };
+
+    // #6967
+    const fn f4() {
+        match Some(0) {
+            Some(x) => Some(x + 1),
+            None => None,
+        };
+    }
+
+    // #7077
+    let s = &String::new();
+    let _: Option<&str> = match Some(s) {
+        Some(s) => Some(s),
+        None => None,
+    };
 }