Skip to content

Mention field punning in the docs for patterns #26108

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
Jun 13, 2015

Conversation

Marwes
Copy link
Contributor

@Marwes Marwes commented Jun 8, 2015

Adds a mention for the short form pattern syntax. Now without creating a PR to my own fork!
#25779

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@brson
Copy link
Contributor

brson commented Jun 8, 2015

r? @steveklabnik

My only comment is that 'punning' is really jargony, and probably can't go without explanation.

@rust-highfive rust-highfive assigned steveklabnik and unassigned brson Jun 8, 2015
@Marwes
Copy link
Contributor Author

Marwes commented Jun 8, 2015

I considered not to mention it but it is the correct term for it so mentioning it is probsbly a good idea. Just calling it "short form" feels harder to remember as well.

@steveklabnik
Copy link
Member

yeah, I am split on this, for the same reason as @brson. We've been trying to eliminate extra jargon as of late.

Also, is 'punning' truly correct here? http://en.wikipedia.org/wiki/Type_punning seems more in line with how i've seen this used.

I know we have a lint if you don't use this syntax, ie, x: x. What does that error message say?

Finally, if we do keep the jargon, it would be nice to put it in the Glossary and link to it.

@Marwes
Copy link
Contributor Author

Marwes commented Jun 8, 2015

Both OCaml and Haskell calls it field punning though so I'd say it is correct. The warning only says that the field can be removed though. I can see why it should be removed though to reduce jargon since it does not help understanding the syntax in it is self. My main reason for adding the mention was more for the sake of it being a mnemonic since there did exist a term for it.

On another note, maybe its worth changing the later examples to use the same form as x : x display a style which is actively discouraged through warnings?

test.rs:3:16: 3:21 warning: the `x:` in this pattern is redundant and can be removed, #[warn(non_shorthand_field_patterns)] on by default
test.rs:3     let Test { x : x } = panic!();

https://realworldocaml.org/v1/en/html/records.html
https://downloads.haskell.org/~ghc/7.0.4/docs/html/users_guide/syntax-extns.html#record-puns

@steveklabnik
Copy link
Member

On another note, maybe its worth changing the later examples to use the same form as x : x display a style which is actively discouraged through warnings?

yes, I have been meaning to do that.

@Marwes
Copy link
Contributor Author

Marwes commented Jun 9, 2015

Maybe introducing the rebinding as sugar on top of the shorter form would be better, something like this for example Marwes@120ec30.

@steveklabnik
Copy link
Member

@Marwes yes, that's great. Would you mind updating this PR with that commit?

@Marwes
Copy link
Contributor Author

Marwes commented Jun 9, 2015

Looks like I created an additional commit as well here due to merging. The high-five bot discouraged rebasing when adding commits so I guess I should leave it as is, or should I squash them?

@steveklabnik
Copy link
Member

@Marwes squashing them is just fine. Thanks again!

r=me after

Explains short form pattern syntax and then introduces the longer
pattern matching as a rebinding of the fields instead.

 rust-lang#25779
@Marwes
Copy link
Contributor Author

Marwes commented Jun 12, 2015

@steveklabnik Done.

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Collaborator

bors commented Jun 12, 2015

📌 Commit 219ddd1 has been approved by steveklabnik

@steveklabnik
Copy link
Member

Thanks so much!

@bors
Copy link
Collaborator

bors commented Jun 13, 2015

⌛ Testing commit 219ddd1 with merge 7c38de8...

bors added a commit that referenced this pull request Jun 13, 2015
Adds a mention for the short form pattern syntax. Now without creating a PR to my own fork!

#25779
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.

5 participants