1 #![warn(clippy::if_then_some_else_none)]
2 #![feature(custom_inner_attributes)]
5 // Should issue an error.
13 // Should issue an error when macros are used.
14 let _ = if matches!(true, true) {
16 Some(matches!(true, false))
21 // Should issue an error. Binary expression `o < 32` should be parenthesized.
23 let _ = x.and_then(|o| if o < 32 { Some(o) } else { None });
25 // Should issue an error. Unary expression `!x` should be parenthesized.
27 let _ = if !x { Some(0) } else { None };
29 // Should not issue an error since the `else` block has a statement besides `None`.
34 eprintln!("false...");
38 // Should not issue an error since there are more than 2 blocks in the if-else chain.
40 println!("foo true!");
43 println!("bar true!");
50 println!("foo true!");
54 println!("bar true!");
59 // Should not issue an error since the `then` block has `None`, not `Some`.
60 let _ = if foo() { None } else { Some("foo is false") };
62 // Should not issue an error since the `else` block doesn't use `None` directly.
63 let _ = if foo() { Some("foo is true") } else { into_none() };
65 // Should not issue an error since the `then` block doesn't use `Some` directly.
66 let _ = if foo() { into_some("foo") } else { None };
70 #![clippy::msrv = "1.49"]
71 // `bool::then` was stabilized in 1.50. Do not lint this
81 #![clippy::msrv = "1.50"]
98 fn into_some<T>(v: T) -> Option<T> {
102 fn into_none<T>() -> Option<T> {