]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/question_mark.rs
iterate List by value
[rust.git] / tests / ui / question_mark.rs
index 57237c52e8c9a4f628a6a0753cd3eb0619842495..1d0ee82b4f7787b5e56445c334b2115066804d67 100644 (file)
@@ -1,3 +1,6 @@
+// run-rustfix
+#![allow(unreachable_code)]
+
 fn some_func(a: Option<u32>) -> Option<u32> {
     if a.is_none() {
         return None;
@@ -58,6 +61,12 @@ pub fn func(&self) -> Option<u32> {
             self.opt
         };
 
+        let _ = if let Some(x) = self.opt {
+            x
+        } else {
+            return None;
+        };
+
         self.opt
     }
 }
@@ -90,11 +99,44 @@ pub fn mov_func_no_use(self) -> Option<Vec<u32>> {
         }
         Some(Vec::new())
     }
+
+    pub fn if_let_ref_func(self) -> Option<Vec<u32>> {
+        let v: &Vec<_> = if let Some(ref v) = self.opt {
+            v
+        } else {
+            return None;
+        };
+
+        Some(v.clone())
+    }
+
+    pub fn if_let_mov_func(self) -> Option<Vec<u32>> {
+        let v = if let Some(v) = self.opt {
+            v
+        } else {
+            return None;
+        };
+
+        Some(v)
+    }
+}
+
+fn func() -> Option<i32> {
+    fn f() -> Option<String> {
+        Some(String::new())
+    }
+
+    if f().is_none() {
+        return None;
+    }
+
+    Some(0)
 }
 
 fn main() {
     some_func(Some(42));
     some_func(None);
+    some_other_func(Some(42));
 
     let copy_struct = CopyStruct { opt: Some(54) };
     copy_struct.func();
@@ -108,4 +150,6 @@ fn main() {
 
     let so = SeemsOption::Some(45);
     returns_something_similar_to_option(so);
+
+    func();
 }