-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.
Description
First, there are currently 474 issues|PRs here that contain "if let", so I hope I'm not duplicating something already discussed.
This idea is quite close to #929, but instead of allowing to && lets, it'd allow to && with a bool.
Basically, the idea looks like this:
if let Some(x) = y && x > 42 {
println!("foo");
} else {
println!("bar");
}
// Would be equivalent to:
if let Some(x) = y {
if x > 42 {
println!("foo");
} else {
println!("bar");
}
} else {
println!("bar");
}This pattern is something that frequently occurred to me, and I'm finding it painful to always look for workarounds.
The constraints to this pattern would be:
- Only && could be used after a let, especially if a || is wanted it must be as a child node of the && (required so that the RHS could be evaluated with the let binding in scope)
- For the time being, it is restricted to one let and one or more && with bools, leaving ideas like
if let Some((a, b)) = x && a > 42 && let Some(c) = b.unwrap()for later (modulo Support && in if let expressions #929)
What do you think about this idea?
Nadrieril, kornelski, shouya, ds84182, kgtkr and 35 moreH2CO3 and velyanH2CO3, BatmanAoD, pyfisch and CatCode79rethab and matzayonc
Metadata
Metadata
Assignees
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.