Skip to content

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

Merged
merged 1 commit into from
May 2, 2015
Merged

Revise @ in patterns section #25058

merged 1 commit into from
May 2, 2015

Conversation

steveklabnik
Copy link
Member

Fixes #25008

@rust-highfive
Copy link
Contributor

r? @nikomatsakis

(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),
Copy link
Member

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)

@huonw
Copy link
Member

huonw commented May 2, 2015

r=me with the range comment.

@steveklabnik
Copy link
Member Author

@bors: r=huonw rollup

@bors
Copy link
Collaborator

bors commented May 2, 2015

📌 Commit 4db3bb7 has been approved by huonw

@steveklabnik
Copy link
Member Author

@bors: r=huonw rollup

@bors
Copy link
Collaborator

bors commented May 2, 2015

📌 Commit df18642 has been approved by huonw

@steveklabnik
Copy link
Member Author

(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 `@`:
Copy link

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. :-)

Copy link

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.

@bors
Copy link
Collaborator

bors commented May 2, 2015

⌛ Testing commit df18642 with merge 0d7d3ec...

bors added a commit that referenced this pull request May 2, 2015
@bors bors merged commit df18642 into rust-lang:master May 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@-pattern documentation in the book is a little misleading
5 participants