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

document field init shorthand #38830

Closed
4 of 5 tasks
nikomatsakis opened this issue Jan 4, 2017 · 19 comments
Closed
4 of 5 tasks

document field init shorthand #38830

nikomatsakis opened this issue Jan 4, 2017 · 19 comments
Assignees
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority

Comments

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jan 4, 2017

RFC 1682 added "field init shorthand" (tracking issue is #37340), which allows you to use a shorthand in struct literals:

struct Foo { x } => struct Foo { x: x }

This is implemented on nightly and we would like to stabilize it, but documentation is required. Here is a list of places where the documentation would need to be updated, kindly prepared by @havvy:

I'm marking this as E-mentor, since updating these docs seems like a pretty good starter bug.

@nikomatsakis nikomatsakis added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools and removed E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Jan 4, 2017
@nikomatsakis nikomatsakis added A-docs C-enhancement Category: An issue proposing an enhancement or a PR with one. P-medium Medium priority labels Jan 4, 2017
@steveklabnik
Copy link
Member

yes, i am very happy to mentor anyone who needs help with this.

@ghost
Copy link

ghost commented Jan 5, 2017

I would like to pick this up.

@steveklabnik
Copy link
Member

@HnGiang great! Please let me know if you need any assistance.

@ghost
Copy link

ghost commented Jan 16, 2017

@steveklabnik sorry for take a while to process, please help me review document in PR #39096

steveklabnik added a commit to steveklabnik/rust that referenced this issue Jan 23, 2017
…nd-38830, r=steveklabnik

Update struct_expr grammar for field init shorthand.

Part of the work for rust-lang#38830 .

r? @steveklabnik
@nikomatsakis
Copy link
Contributor Author

What is the status of this work now? :)

@steveklabnik
Copy link
Member

@nikomatsakis basically, until we have the bookshelf, we're not landing doc PRs until they're the last thing holding up stabilization. #39096 has some outstanding issues with it as well that need to be addressed before it's mergable.

@nikomatsakis
Copy link
Contributor Author

@steveklabnik ok. To be clear, I think that a doc PR is indeed the only thing holding up stabilization here, so once those issues are addressed, I think we ought to merge.

@steveklabnik
Copy link
Member

Okay. so, should we be doing that right now, to land stuff before the next release? or should we be waiting until after the branch? Has the next beta been branched?

@nikomatsakis
Copy link
Contributor Author

@steveklabnik I don't care too much about whether this makes it into the next beta or not, we don't have to stress, but I would not delay either.

@ghost
Copy link

ghost commented Feb 3, 2017

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.

@ghost
Copy link

ghost commented Feb 6, 2017

I'd like to help in this one, I don't know a lot but I'm willing to learn :)

@steveklabnik
Copy link
Member

@z1mvader thank you! As far as docs go, #39459 has most of the work in it; maybe take a look at that and see if it makes sense to you? Leave a comment either way 😄

frewsxcv added a commit to frewsxcv/rust that referenced this issue 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 issue 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
@est31
Copy link
Member

est31 commented Feb 12, 2017

As the changelog is created always when doing releases (at least this history seems to indicate that), I think nothing needs to be changed in the Rust git repo, right? So only Rust by example remains for this issue to be resolved?

@chriskrycho
Copy link
Contributor

Though not required for this, I've gone ahead and made an example, so you can mark that item as done as well!

frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 16, 2017
Stabilize field init shorthand

Closes rust-lang#37340.

~Still blocked by the documentation issue rust-lang#38830.~ EDIT: seems that all parts required for stabilisation are fixed, so its not blocked.
bors added a commit that referenced this issue Feb 16, 2017
Stabilize field init shorthand

Closes #37340.

~Still blocked by the documentation issue #38830.~ EDIT: seems that all parts required for stabilisation are fixed, so its not blocked.
@steveklabnik steveklabnik added A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools and removed A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels Mar 10, 2017
@steveklabnik steveklabnik self-assigned this Mar 15, 2017
@steveklabnik
Copy link
Member

we have both rust-lang/rust-by-example#844 and rust-lang/rust-by-example#837 so i think this is all done now!

@zeyangl
Copy link

zeyangl commented Feb 13, 2018

I know this feature is already implemented and closed. I'm trying to get it to work but fails for some reason.

struct Color2
{
    pub r: i32,
}

fn handle_file()
{
    let tc = Color2{0};
}

fn main()
{
    println!("started...");
    handle_file();
}

extremely obvious code here. Whenever I compile and run it. I get this error:

error: expected identifier, found `0`
  --> src/main.rs:19:21
   |
19 |     let tc = Color2{0};
   |              ------ ^ expected identifier
   |              |
   |              while parsing this struct

I ran both 1.2.3 stable and nightly on this, same result.
Is there something really obvious that i am not getting?
Appreciate the help!

@Havvy
Copy link
Contributor

Havvy commented Feb 13, 2018

Yes. The shorthand lets you substitute e.g. r: r inside of Color2{r: r} with just r so it'd be Color2{r}. It doesn't let you pass values anonymously, so you'd want to do Color2{r: 0} and not use the shorthand in your example, or if you really want to use the shorthand... let r = 0; let tc = Color2{ r };

@est31
Copy link
Member

est31 commented Feb 13, 2018

Adding to that, even though this works:

struct Tea(u32, u32);

fn main() {
    let t = Tea {
        0: 2,
        1: 3,
    };
}

This doesn't:

struct Tea(u32, u32);

fn main() {
    let 0 = 2;
    let 1 = 3;
    let t = Tea {
        0,
        1,
    };
}

@steveklabnik
Copy link
Member

I'm trying to get it to work but fails for some reason.

Generally, users.rust-lang.org or StackOverflow are better places to get help than adding more comments on closed bugs! In this case, you got an answer though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

6 participants