-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add if-while-let_multiple_patterns RFC #937
Conversation
…et_multiple_patterns.md
Discussed in #935 |
Should this RFC also propose that exhaustive normal e.g.
|
@gankro: I agree that that would be more consistent, but I think that would make more sense to open as a seperate RFC. Alternatively, a RFC could change |
I would opt for a separate RfC for that. |
(I agree with this RfC, btw) |
In fact if we also use |
@glaebhoerl Couldn't all of those be written with |
@pcwalton Sure; I only meant to point out that if we change the |
That's a very interesting question, and it doesn't seem like it would hurt the language as such. However, this seems like an orthogonal issue. |
What's the verdict on this? Most people here and in #935 seem to be in agreement that this is a useful addition to the language, but it also opens up various questions regarding additional constructs such as nested |
@Munksgaard my inclination is that this is a nice-to-have feature that we don't need presently. It's very tempting to add to Rust every nice convenience, but we have to exercise restraint. |
I'm not convinced that this is something we should do. In general, I'm in favor of making For example, if let a = foo(), let b = a.bar(), let c = b.baz() where c > 2, let d = c.quux() {
// do something with d
} else {
// some expression in that chain failed
} (this can actually be shortened slightly by dropping the 2nd and 3rd This is equivalent to var success = false
if let a = foo() {
if let b = a.bar() {
if let c = b.baz() where c > 2 {
if let d = c.quux() {
success = true
// do something with d
}
}
}
}
if !success {
// some expression in that chain failed
} This turns out to be a useful construct, and I'd like to eventually get something similar into Rust. But if we loosen the More generally, making changes to make |
That is not true. The idea of if let was circulated in the /mozilla/rust issue tracker long before Swift was announced. |
Credit goes to @kevina |
@mahkoh I wrote the |
That just means that the RFC was inspired by swift. The idea to destructure in |
To contribute something on-topic: I share @kballard's concerns. The following constructs seem interesting too and one would have to think about how they interact with this RFC: if let Some(x) = x1 || let Some(x) = x2
if (let Some(ref x) = x1 && x > 0) || let Some(ref x) = x2 |
Although this is a cool feature, per general concerns about feature creep, I'm closing this RFC without accepting it. Thank you. |
This has already been implemented in rust-lang/rust#23034