Skip to content
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

[WIP] Document field init shorthand #39096

Closed
wants to merge 3 commits into from
Closed

[WIP] Document field init shorthand #39096

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jan 16, 2017

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @steveklabnik (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. Due to 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.

@ghost ghost mentioned this pull request Jan 16, 2017
5 tasks
@@ -117,6 +117,28 @@ fn main() {
}
```

We can initializing a data structure (struct, enum, union) with named fields, by writing `fieldname` as a shorthand for `fieldname: fieldname`. This allows a compact syntax for initialization, with less duplication:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"intializing" -> initialize

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence doesn't read write to me at all. I would replace all of a data structure (struct, enum, union) with named fields with named fields.

I would also add a sentence saying that a variable of the name of the field also has to be in scope.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems wrong to me.
I would write:
Initialization of a data structure can be simplified if fields of the data structure are initialized with variables which has same names as the fields.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @KalitaAlexey 's suggestion.


When initializing a data structure (struct, enum, union) with named fields, allow writing `fieldname` as a shorthand for `fieldname: fieldname`. This allows a compact syntax for initialization, with less duplication.

In the initializer for a `struct` with named fields, a `union` with named fields, or an enum variant with named fields, accept an identifier `field` as a shorthand for `field: field`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"a union" -> "an union"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an English speaker, "a union" sounds write to me. Silly little quirks in this language...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English is way too complicated...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always a simple rule, but there are a lot of them, which makes the whole complicated.

@ghost ghost changed the title document field init shorthand [WIP] Document field init shorthand Jan 16, 2017
@steveklabnik
Copy link
Member

Thank you so much @HnGiang ! Could you also wrap this to 80 columns, please?

@bors
Copy link
Contributor

bors commented Jan 24, 2017

☔ The latest upstream changes (presumably #39260) made this pull request unmergeable. Please resolve the merge conflicts.

@steveklabnik
Copy link
Member

Ping @HnGiang ! This is now the last thing that needs to be done before this can be made stable; do you know when you'll be able to fix up this PR?

@ghost
Copy link
Author

ghost commented Feb 3, 2017

@steveklabnik: I haven't been available these days due to the big holiday in my country, so I couldn't reach the topic. At the moment, I have some troubles in work and cannot fix these problems, I will ask @phungleson for help. Thanks.

@steveklabnik
Copy link
Member

@HnGiang no worries! I totally understand; I hope your holiday went well! Good luck with the work situation. I will close in favor of #39459

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 8, 2017
…c, r=steveklabnik

Fix short hand struct doc

Don't want to discredit @HnGiang effort on this issue.

I just want to lend a hand to fix this issue rust-lang#38830, it is a very nice feature and is seemingly completed.

Fixes rust-lang#39096

r? @steveklabnik
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 8, 2017
…c, r=steveklabnik

Fix short hand struct doc

Don't want to discredit @HnGiang effort on this issue.

I just want to lend a hand to fix this issue rust-lang#38830, it is a very nice feature and is seemingly completed.

Fixes rust-lang#39096

r? @steveklabnik
steveklabnik added a commit to rust-lang/book that referenced this pull request Mar 23, 2017
From RFC 1682.

This is an updated version of #405.

cc rust-lang/rust#39096
gypsydave5 pushed a commit to gypsydave5/book that referenced this pull request Nov 17, 2017
From RFC 1682.

This is an updated version of rust-lang#405.

cc rust-lang/rust#39096
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.

6 participants