2 #![warn(clippy::option_if_let_else)]
4 fn bad1(string: Option<&str>) -> (bool, &str) {
5 string.map_or((false, "hello"), |x| (true, x))
8 fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> {
11 } else { string.map_or(Some((false, "")), |x| Some((true, x))) }
14 fn unop_bad(string: &Option<&str>, mut num: Option<i32>) {
15 let _ = string.map_or(0, |s| s.len());
16 let _ = num.as_ref().map_or(&0, |s| s);
17 let _ = num.as_mut().map_or(&mut 0, |s| {
21 let _ = num.as_ref().map_or(&0, |s| s);
22 let _ = num.map_or(0, |mut s| {
26 let _ = num.as_mut().map_or(&mut 0, |s| {
32 fn longer_body(arg: Option<u32>) -> u32 {
39 fn test_map_or_else(arg: Option<u32>) {
40 let _ = arg.map_or_else(|| {
45 }, |x| x * x * x * x);
48 fn negative_tests(arg: Option<u32>) -> u32 {
49 let _ = if let Some(13) = arg { "unlucky" } else { "lucky" };
51 let _ = if let Some(x) = arg {
57 let _ = if let Some(x) = arg {
66 let optional = Some(5);
67 let _ = optional.map_or(5, |x| x + 2);
69 let _ = else_if_option(None);
70 unop_bad(&None, None);
71 let _ = longer_body(None);
72 test_map_or_else(None);
73 let _ = negative_tests(None);