2 #![warn(clippy::option_if_let_else)]
3 #![allow(clippy::redundant_closure)]
4 #![allow(clippy::ref_option_ref)]
6 fn bad1(string: Option<&str>) -> (bool, &str) {
7 string.map_or((false, "hello"), |x| (true, x))
10 fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> {
13 } else { string.map_or(Some((false, "")), |x| Some((true, x))) }
16 fn unop_bad(string: &Option<&str>, mut num: Option<i32>) {
17 let _ = string.map_or(0, |s| s.len());
18 let _ = num.as_ref().map_or(&0, |s| s);
19 let _ = num.as_mut().map_or(&mut 0, |s| {
23 let _ = num.as_ref().map_or(&0, |s| s);
24 let _ = num.map_or(0, |mut s| {
28 let _ = num.as_mut().map_or(&mut 0, |s| {
34 fn longer_body(arg: Option<u32>) -> u32 {
41 fn impure_else(arg: Option<i32>) {
42 let side_effect = || {
46 let _ = arg.map_or_else(|| side_effect(), |x| x);
49 fn test_map_or_else(arg: Option<u32>) {
50 let _ = arg.map_or_else(|| {
55 }, |x| x * x * x * x);
58 fn negative_tests(arg: Option<u32>) -> u32 {
59 let _ = if let Some(13) = arg { "unlucky" } else { "lucky" };
61 let _ = if let Some(x) = arg {
67 let _ = if let Some(x) = arg {
76 let optional = Some(5);
77 let _ = optional.map_or(5, |x| x + 2);
79 let _ = else_if_option(None);
80 unop_bad(&None, None);
81 let _ = longer_body(None);
82 test_map_or_else(None);
83 let _ = negative_tests(None);
84 let _ = impure_else(None);