Open
Description
Code
fn main() {
let x = Some(42);
if let Some(_) = x
&& Some(x) = x
{}
}
Current output
Update:
error: expected expression, found `let` statement
--> src/main.rs:3:8
|
3 | if let Some(_) = x
| ^^^^^^^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
help: you might have meant to continue the let-chain
|
4 | && let Some(x) = x
| +++
help: you might have meant to compare for equality
|
4 | && Some(x) == x
| +
error[E0308]: mismatched types
--> src/main.rs:4:12
|
4 | && Some(x) = x
| ^^^^^^^ expected `bool`, found `Option<Option<{integer}>>`
|
= note: expected type `bool`
found enum `Option<Option<{integer}>>`
help: use `Option::is_some` to test if the `Option` has a value
|
4 | && Some(x).is_some() = x
| ++++++++++
error[E0308]: mismatched types
--> src/main.rs:3:8
|
3 | if let Some(_) = x
| ________^
4 | | && Some(x) = x
| |______________________^ expected `bool`, found `()`
Previously:
error: expected expression, found `let` statement
--> src/main.rs:3:8
|
3 | if let Some(_) = x
| ^^^^^^^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
error[E0308]: mismatched types
--> src/main.rs:4:12
|
4 | && Some(x) = x
| ^^^^^^^ expected `bool`, found `Option<Option<{integer}>>`
|
= note: expected type `bool`
found enum `Option<Option<{integer}>>`
help: use `Option::is_some` to test if the `Option` has a value
|
4 | && Some(x).is_some() = x
| ++++++++++
error[E0308]: mismatched types
--> src/main.rs:3:8
|
3 | if let Some(_) = x
| ________^
4 | | && Some(x) = x
| |______________________^ expected `bool`, found `()`
Desired output
Edit: we now provide appropriate suggestions in the first diagnostic, but we should notice that this should have been a let
chain and silence the E0308 errors.
error: let-chain with missing `let`
--> src/main.rs:3:8
|
3 | if let Some(_) = x
| --------------- let-chain starting here
4 | && Some(x) = x
| ^^^^^^^^^^^ expected `let` expression, found assignment
|
help: add `let` before the expression
|
4 | && let Some(x) = x
| +++
Rationale and extra context
No response
Other cases
No response
Anything else?
No response