-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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?
cramertj, ExpHP and sivizius
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.