]> 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 b0c203f06375c1b0120a8431189eebab61fc0cdb..dee80d26bd976d93fda3f72fd0ce3a4cd65c3307 100644 (file)
@@ -9,7 +9,7 @@ fn bad1(string: Option<&str>) -> (bool, &str) {
     }
 }
 
-fn bad2(string: Option<&str>) -> Option<(bool, &str)> {
+fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> {
     if string.is_none() {
         None
     } else if let Some(x) = string {
@@ -19,6 +19,30 @@ fn bad2(string: Option<&str>) -> Option<(bool, &str)> {
     }
 }
 
+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 {
     if let Some(x) = arg {
         let y = x * x;
@@ -60,7 +84,8 @@ fn main() {
     let optional = Some(5);
     let _ = if let Some(x) = optional { x + 2 } else { 5 };
     let _ = bad1(None);
-    let _ = bad2(None);
+    let _ = else_if_option(None);
+    unop_bad(&None, None);
     let _ = longer_body(None);
     test_map_or_else(None);
     let _ = negative_tests(None);