Skip to content

fix issue-144595#156545

Open
bb1yd wants to merge 5 commits into
rust-lang:mainfrom
bb1yd:issue-144595
Open

fix issue-144595#156545
bb1yd wants to merge 5 commits into
rust-lang:mainfrom
bb1yd:issue-144595

Conversation

@bb1yd
Copy link
Copy Markdown
Contributor

@bb1yd bb1yd commented May 13, 2026

I close the previous PR because it's too messy

relevant issue:#144595

I fix this issue by calling look_ahead to check if the user write a name field in the tuple struct, then try to recover after calling parse_ty

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 13, 2026
@bb1yd bb1yd marked this pull request as ready for review May 13, 2026 12:22
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 13, 2026

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

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

rustbot commented May 13, 2026

r? @mejrs

rustbot has assigned @mejrs.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, parser
  • compiler, parser expanded to 73 candidates
  • Random selection from 16 candidates

@bb1yd bb1yd mentioned this pull request May 13, 2026
@qaijuang
Copy link
Copy Markdown
Contributor

No test ?

@rustbot

This comment has been minimized.

@bb1yd
Copy link
Copy Markdown
Contributor Author

bb1yd commented May 14, 2026

I have added a test. Thank you.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 14, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Copy link
Copy Markdown
Contributor

@mejrs mejrs left a comment

Choose a reason for hiding this comment

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

FWIW I don't think your original PR was "too messy", or whatever that meant. No need to close and open a new one 🙂

Can you change the output to more closely represent the output suggested in #144595?

Let's keep

expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`

and add help messages to it. Not replace the error entirely. I think it's much more likely that the user made a typo than that they were mistaken about the difference between tuple and regular structs.

Some meta nits: please try to minimize irrelevant changes to keep the PR easier to review.

View changes since this review

Comment thread compiler/rustc_parse/src/parser/item.rs Outdated
Comment thread compiler/rustc_parse/src/parser/item.rs Outdated
Comment thread compiler/rustc_parse/src/parser/item.rs
@rustbot rustbot 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 14, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 14, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@bb1yd
Copy link
Copy Markdown
Contributor Author

bb1yd commented May 15, 2026

Oops, they are changes from early iterations and I forgot to change them back.

Comment thread tests/ui/parser/field-name-in-tuple-struct.rs Outdated
@bb1yd
Copy link
Copy Markdown
Contributor Author

bb1yd commented May 16, 2026

@rustbot ready

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

bb1yd commented May 16, 2026

I undo irrelevant changes and change the error message to expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:` and use diagnostic struct to generate help message.

let mut err = p.dcx().struct_span_err(p.token.span,
"expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`",
);
err.span_label(p.token.span,"expected one of 7 possible tokens");
Copy link
Copy Markdown
Contributor

@mejrs mejrs May 16, 2026

Choose a reason for hiding this comment

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

You can't hard code an error message like this, it's far too brittle. Please just append the help message to the existing error.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The original error is created in parse_paren_comma_seq (it didn't find a comma). I'm not sure how to capture that error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's in ret.

So you can do something like...

self.parse_paren_comma_seq(|p| { 
   // stuff
})
 .map(|(r, _)| r)
.map_err(|mut e| {
    e.help("oh no");
    e
})

That way you also don't end up indenting the entirety of parse_paren_comma_seq, which should help with the messyness of this pr :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I understand, but in this approach parse_paren_comma_seq will exit at the first colon and we can only report the first name field error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Or do you want the code to continue parse the tuple field and find every name field in map_err?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Generally rustc does try to "keep going" and report more errors if possible. So, I think "yes". I guess it depends on what it ends up looking like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants