Description
fn nowork(a: Option<u32>, b: Option<u32>) -> bool {
if let Some(x) = a { true } else { false }
&&
if let Some(y) = a { true } else { false }
}
fn work(a: Option<u32>, b: Option<u32>) -> bool {
let z = if let Some(x) = a { true } else { false }
&&
if let Some(y) = a { true } else { false };
z
}
Error:
error[E0308]: mismatched types
--> src/main.rs:2:26
|
2 | if let Some(x) = a { true } else { false }
| ^^^^ expected (), found bool
|
= note: expected type `()`
found type `bool`
error[E0308]: mismatched types
--> src/main.rs:2:40
|
2 | if let Some(x) = a { true } else { false }
| ^^^^^ expected (), found bool
|
= note: expected type `()`
found type `bool`
error[E0308]: mismatched types
--> src/main.rs:3:5
|
1 | fn nowork(a: Option<u32>, b: Option<u32>) -> bool {
| ---- expected `bool` because of return type
2 | if let Some(x) = a { true } else { false }
3 | / &&
4 | | if let Some(y) = a { true } else { false }
| |______________________________________________^ expected bool, found &&bool
|
= note: expected type `bool`
found type `&&bool`
Am I missing something? Why is the first one not allowed, but the second one?