-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Revise @ in patterns section #25058
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
Revise @ in patterns section #25058
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
let x = 5; | ||
|
||
match x { | ||
e @ 1 ... 5 | e @ 2 ... 6 => println!("got a range element {}", e), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be more illustrative to have the ranges be disjoint? (e.g. the second one could start at 8)
r=me with the range comment. |
@bors: r=huonw rollup |
📌 Commit 4db3bb7 has been approved by |
@bors: r=huonw rollup |
📌 Commit df18642 has been approved by |
(forgot to actually commit the change) |
@@ -70,8 +70,7 @@ This prints `something else` | |||
|
|||
# Bindings | |||
|
|||
If you’re matching multiple things, via a `|` or a `...`, you can bind | |||
the value to a name with `@`: | |||
You can bind values to names with `@`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, could we be more elaborate here, maybe? The point of @
is that you can both bind the whole value and destructure it in the same pattern. If one only wanted to bind the value to a name, they could use an identifier.
See what I mean? I can't quite put it into words myself. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@steveklabnik I know this is merged but I wonder if you think the above is worth addressing separately.
Fixes #25008