]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/option_if_let_else.rs
Auto merge of #5771 - montrivo:bugfix/single-match-else, r=matthiaskrgr
[rust.git] / tests / ui / option_if_let_else.rs
index 7c43fbea373f3653f35196d92e1347c8c2c1ed74..dee80d26bd976d93fda3f72fd0ce3a4cd65c3307 100644 (file)
@@ -19,12 +19,28 @@ fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> {
     }
 }
 
-fn unop_bad(string: &Option<&str>) -> usize {
-    if let Some(s) = *string {
-        s.len()
+fn unop_bad(string: &Option<&str>, mut num: Option<i32>) {
+    let _ = if let Some(s) = *string { s.len() } else { 0 };
+    let _ = if let Some(s) = &num { s } else { &0 };
+    let _ = if let Some(s) = &mut num {
+        *s += 1;
+        s
+    } else {
+        &mut 0
+    };
+    let _ = if let Some(ref s) = num { s } else { &0 };
+    let _ = if let Some(mut s) = num {
+        s += 1;
+        s
     } else {
         0
-    }
+    };
+    let _ = if let Some(ref mut s) = num {
+        *s += 1;
+        s
+    } else {
+        &mut 0
+    };
 }
 
 fn longer_body(arg: Option<u32>) -> u32 {
@@ -69,7 +85,7 @@ fn main() {
     let _ = if let Some(x) = optional { x + 2 } else { 5 };
     let _ = bad1(None);
     let _ = else_if_option(None);
-    let _ = unop_bad(&None);
+    unop_bad(&None, None);
     let _ = longer_body(None);
     test_map_or_else(None);
     let _ = negative_tests(None);