]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/option_if_let_else.fixed
Auto merge of #5301 - JarredAllen:option_if_let_else, r=flip1995
[rust.git] / tests / ui / option_if_let_else.fixed
index 80b162714acaaa6977c450530790ad1549100361..695a460cc4edfda0a16871c1aa0b3f1498359271 100644 (file)
@@ -11,8 +11,22 @@ fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> {
     } else { string.map_or(Some((false, "")), |x| Some((true, x))) }
 }
 
-fn unop_bad(string: &Option<&str>) -> usize {
-    (*string).map_or(0, |s| s.len())
+fn unop_bad(string: &Option<&str>, mut num: Option<i32>) {
+    let _ = string.map_or(0, |s| s.len());
+    let _ = num.as_ref().map_or(&0, |s| s);
+    let _ = num.as_mut().map_or(&mut 0, |s| {
+        *s += 1;
+        s
+    });
+    let _ = num.as_ref().map_or(&0, |s| s);
+    let _ = num.map_or(0, |mut s| {
+        s += 1;
+        s
+    });
+    let _ = num.as_mut().map_or(&mut 0, |s| {
+        *s += 1;
+        s
+    });
 }
 
 fn longer_body(arg: Option<u32>) -> u32 {
@@ -53,7 +67,7 @@ fn main() {
     let _ = optional.map_or(5, |x| x + 2);
     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);