1 #![allow(unused_braces, unused_variables, dead_code)]
2 #![allow(clippy::collapsible_else_if, clippy::let_unit_value)]
3 #![warn(clippy::manual_let_else)]
4 // Ensure that we don't conflict with match -> if let lints
5 #![warn(clippy::single_match_else, clippy::single_match)]
7 fn f() -> Result<u32, u32> {
11 fn g() -> Option<()> {
15 fn h() -> (Option<()>, Option<()>) {
25 fn build_enum() -> Variant {
33 Some(v_some) => v_some,
38 Some(v_some) => v_some,
43 // More complex pattern for the identity arm and diverging arm
45 (Some(_), Some(_)) | (None, None) => continue,
46 (Some(v), None) | (None, Some(v)) => v,
48 // Custom enums are supported as long as the "else" arm is a simple _
49 let v = match build_enum() {
51 Variant::Bar(v) | Variant::Baz(v) => v,
55 // There is a _ in the diverging arm
56 // TODO also support unused bindings aka _v
62 // Err(()) is an allowed pattern
63 let v = match f().map_err(|_| ()) {
68 let f = Variant::Bar(1);
70 let _value = match f {
71 Variant::Bar(_) | Variant::Baz(_) => (),
77 // Multiple diverging arms
80 (None, Some(_v)) => return,
84 // Multiple identity arms
91 // No diverging arm at all, only identity arms.
92 // This is no case for let else, but destructuring assignment.
98 // The identity arm has a guard
100 Some(v) if g().is_none() => v,
104 // The diverging arm has a guard
106 Err(v) if v > 0 => panic!(),
110 // The diverging arm creates a binding
113 Err(e) => panic!("error: {e}"),
116 // Custom enum where the diverging arm
117 // explicitly mentions the variant
118 let v = match build_enum() {
119 Variant::Foo => return,
120 Variant::Bar(v) | Variant::Baz(v) => v,
123 // The custom enum is surrounded by an Err()
124 let v = match Err(build_enum()) {
125 Ok(v) | Err(Variant::Bar(v) | Variant::Baz(v)) => v,
126 Err(Variant::Foo) => return,