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

Issue #50974 : Suboptimal error in case of duplicate , in struct constructor #51184

Merged
merged 7 commits into from
Jun 22, 2018

Conversation

lambtowolf
Copy link
Contributor

Fixes #50974

@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 @nikomatsakis (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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 29, 2018
@@ -767,6 +767,9 @@ impl<'a> Parser<'a> {
err.span_label(self.span, format!("expected identifier, found {}", token_descr));
} else {
err.span_label(self.span, "expected identifier");
if self.token == token::Comma {
err.span_suggestion(self.span, "remove this comma", ",".into());
Copy link
Contributor

Choose a reason for hiding this comment

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

The third argument here should be an empty string. This will change the output to help: remove this comma.

@@ -767,6 +767,9 @@ impl<'a> Parser<'a> {
err.span_label(self.span, format!("expected identifier, found {}", token_descr));
} else {
err.span_label(self.span, "expected identifier");
if self.token == token::Comma {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is the best thing to do, as is. I would only add this suggestion if the next token is indeed an ident:

    if self.token == token::Comma && self.look_ahead(1, |t| *t.is_ident()) {

Copy link
Contributor Author

@lambtowolf lambtowolf May 30, 2018

Choose a reason for hiding this comment

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

I think it will still be useful even if the next token is not an identifier. We should not ever have 2 commas in a row in a struct constructor.

struct Bar {
    a: u8,
    b: u8
}

let foo = Bar {
    a: 42,
    b: 42,,
};

In this example, the user still has to remove the duplicate comma to get his code to compile.

self.recover_stmt();
break;

if self.token != token::Comma {
Copy link
Contributor

Choose a reason for hiding this comment

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

This confuses me a bit — when does this , token get dropped, if not by recover_stmt?

Copy link
Contributor Author

@lambtowolf lambtowolf May 30, 2018

Choose a reason for hiding this comment

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

It gets dropped afterwards at line 2541 :

self.expect_one_of(&[token::Comma], &[token::CloseDelim(token::Brace)])

Should I add a comment to clarify this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see now. Yes, put a comment if you don't mind.

@rust-highfive

This comment has been minimized.

@nikomatsakis nikomatsakis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2018
@nikomatsakis
Copy link
Contributor

@lambtowolf think you can add that explanatory comment? =)

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 5, 2018

📌 Commit 01559fb has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 5, 2018
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jun 5, 2018
Issue rust-lang#50974 : Suboptimal error in case of duplicate `,` in struct constructor

Fixes rust-lang#50974
@bors
Copy link
Contributor

bors commented Jun 6, 2018

🔒 Merge conflict

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 6, 2018
@nikomatsakis
Copy link
Contributor

@lambtowolf Needs rebase 😿

@pietroalbini
Copy link
Member

@lambtowolf you should rebase on master, even if you don't see any conflict at first glance.

@pietroalbini
Copy link
Member

Ping from triage @lambtowolf! It's been a while since we heard from you, will you have time to work on this again?

@bors
Copy link
Contributor

bors commented Jun 21, 2018

🔒 Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase?

Assuming self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout master (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self master --force-with-lease (update this PR)

You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial.

Please avoid the "Resolve conflicts" button on GitHub. It uses git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
Auto-merging src/libsyntax/parse/parser.rs
CONFLICT (file/directory): There is a directory with name src/libbacktrace in heads/homu-tmp. Adding src/libbacktrace as src/libbacktrace~HEAD
Automatic merge failed; fix conflicts and then commit the result.

1 similar comment
@bors
Copy link
Contributor

bors commented Jun 22, 2018

🔒 Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase?

Assuming self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout master (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self master --force-with-lease (update this PR)

You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial.

Please avoid the "Resolve conflicts" button on GitHub. It uses git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
Auto-merging src/libsyntax/parse/parser.rs
CONFLICT (file/directory): There is a directory with name src/libbacktrace in heads/homu-tmp. Adding src/libbacktrace as src/libbacktrace~HEAD
Automatic merge failed; fix conflicts and then commit the result.

@pietroalbini
Copy link
Member

Rebased this on top of the latest master.

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Jun 22, 2018

📌 Commit a99767f has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 22, 2018
@bors
Copy link
Contributor

bors commented Jun 22, 2018

⌛ Testing commit a99767f with merge 01dbfda...

bors added a commit that referenced this pull request Jun 22, 2018
Issue #50974 : Suboptimal error in case of duplicate `,` in struct constructor

Fixes #50974
@bors
Copy link
Contributor

bors commented Jun 22, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 01dbfda to master...

@bors bors merged commit a99767f into rust-lang:master Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants