As I said in the post you can also write this:
if let (Some(x), true) = (my_option, expr) {
But then it doesn't short-circuit. (expr is evaluated in all cases, even when the optional is None).Both approaches are also weird. It'd be much better to just fix the language to make the obvious thing work.
[1] https://rust-lang.github.io/rfcs/2497-if-let-chains.html
Me too. But that often makes my logic worse. Its quite common to want to share the same code in the else branch, for example:
if let Some(val) = opt {
if expr {
// ....
} else {
do_complex_stuff();
}
} else {
do_complex_stuff();
}
I don't want to copy+paste that complex code in two places. And you can fix that in turn with a named block & named break statements or a function - but .... whyyyyy? Why is this even a thing? The solution is so obvious. The RFC you linked to fix it is fine, and 6 years old now. My sister has a child in grade school who was born after that RFC was drafted.Yes, you can work around this hole in the language any number of ways with ugly code. But I don't want to do that. I want to use a good language.
Yes, I do want a good programming language. I agree its relatively minor compared to the other issues I talked about in the blog post.
In what way is this at odds with other aspects of the language? If its at odds with the rest of the language, why is this feature being added?