2 #![allow(unreachable_code)]
3 #![allow(clippy::unnecessary_wraps)]
5 fn some_func(a: Option<u32>) -> Option<u32> {
11 fn some_other_func(a: Option<u32>) -> Option<u32> {
20 pub enum SeemsOption<T> {
25 impl<T> SeemsOption<T> {
26 pub fn is_none(&self) -> bool {
28 SeemsOption::None => true,
29 SeemsOption::Some(_) => false,
34 fn returns_something_similar_to_option(a: SeemsOption<u32>) -> SeemsOption<u32> {
36 return SeemsOption::None;
42 pub struct CopyStruct {
48 pub fn func(&self) -> Option<u32> {
53 let _ = Some(self.opt?);
62 pub struct MoveStruct {
63 pub opt: Option<Vec<u32>>,
67 pub fn ref_func(&self) -> Option<Vec<u32>> {
73 pub fn mov_func_reuse(self) -> Option<Vec<u32>> {
79 pub fn mov_func_no_use(self) -> Option<Vec<u32>> {
84 pub fn if_let_ref_func(self) -> Option<Vec<u32>> {
85 let v: &Vec<_> = self.opt.as_ref()?;
90 pub fn if_let_mov_func(self) -> Option<Vec<u32>> {
97 fn func() -> Option<i32> {
98 fn f() -> Option<String> {
107 fn func_returning_result() -> Result<i32, i32> {
111 fn result_func(x: Result<i32, i32>) -> Result<i32, i32> {
117 let y = if let Ok(x) = x {
125 let _ = if let Ok(x) = func_returning_result() {
132 if func_returning_result().is_err() {
133 return func_returning_result();
146 fn obj(_: i32) -> Result<(), NotOption> {
147 Err(NotOption::First)
150 fn f() -> NotOption {
152 return NotOption::None;
160 some_other_func(Some(42));
162 let copy_struct = CopyStruct { opt: Some(54) };
165 let move_struct = MoveStruct {
166 opt: Some(vec![42, 1337]),
168 move_struct.ref_func();
169 move_struct.clone().mov_func_reuse();
170 move_struct.mov_func_no_use();
172 let so = SeemsOption::Some(45);
173 returns_something_similar_to_option(so);
177 let _ = result_func(Ok(42));