-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Related: rust-lang/rust#28449
Currently if let
desugars to a match with guards. Using the example from the related post:
let mut f = Some(1);
if let Some(a) = f {
bar();
} else if f.as_mut().is_some() {
baz();
}
Desugars to
match f {
Some(a) => {bar();}
_ if f.as_mut().is_some() {baz();}
_ => {}
}
However, this leads to f
being borrowed in the else if
which is truly annoying. Instead, I propose the following desugaring:
if match f {Some(_) => true, _ => false } {
let Some(a) = f;
{ bar(); }
} else if f.as_mut().is_some() {
baz();
}
Which (I believe) does not suffer from the same problem.
One unanswered question is: does non-lexical lifetimes solve this?
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.