-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
let-else does not support else if
#111910
Comments
I'd be willing to work on this if this is desired. |
FTR this is the real world code that my comment in the let else tracking issue was referring to (the link bitrotted): rust/compiler/rustc_codegen_ssa/src/back/link.rs Lines 189 to 198 in 72d6606
Nowadays it's an if let but one could imagine code afterwards that one doesn't want to be affected by rightward drift. IMO it's a good idea to have it, but back when It also has low conflict potential with other extension proposals for let Foo::BarA(foo) = hi
else if let Foo::BarB(foo) { return; } // We could theoretically allow dropping the expr here and just match on the `hi` expr
else if let Foo::BarC(foo, foo2) { return; }
else if true { // Is this tail if confusing? It does *not* try to do something with the `hi` expr
panic!()
} else {
return;
}; or the match equivalent: let Foo::BarA(foo) = hi
else match {
Foo::BarC(foo) => panic!(),
Foo::BarD(foo, foo2) => panic!(),
_ => panic!(),
}; |
Hum, it is unrelated but I would like to chime-in to also mention the possibility of using
|
(Not speaking for the team) Personally, I'm not inclined to do this. We generally don't have "remove one level of extra indentation" features, and (more importantly) I think that if we're going to extend this, it would be something that more directly integrates with the pattern behaviour. Like there was the previous discussion of something like (I consider normal |
to me this is not about "remove one level of extra indentation" but much rather that |
I guess I don't see it that way as there's no (For example, |
I'm similarly not inclined to do this; |
this is a discussion about syntactic sugar, it can never unlock functionality you couldn't get otherwise. Looking at #111910 (comment) as an example where this might be useful: let Some((path, _)) = &used_crate_source.rlib
else if used_crate_source.rmeta.is_some() {
return Err(format!(
"could not find rlib for: `{}`, found rmeta (metadata) file",
name
));
} else {
return Err(format!("could not find rlib for: `{}`", name));
}; vs let Some((path, _)) = &used_crate_source.rlib else {
if used_crate_source.rmeta.is_some() {
return Err(format!(
"could not find rlib for: `{}`, found rmeta (metadata) file",
name
));
} else {
return Err(format!("could not find rlib for: `{}`", name));
}
}; I think the formatting required for I still think having the option to use Going to drop the nomination because this issue doesn't feel important enough to stay nominated for months. |
results in the following error but should compile imo:
the improved diagnostic has been added in #89974 which refers to #87335 (comment) by @joshtriplett:
I personally disagree with "and I don't think we should". For me this not working was fairly surprising and conflicts with my intuition of
let else
as a shorthand foror as stated in the RFC
I would like to add support for this myself or mentor someone adding this. I am not sure what process is required here. If not desired, please FCP close this.
The text was updated successfully, but these errors were encountered: