fix issue-144595#156545
Conversation
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
|
r? @mejrs rustbot has assigned @mejrs. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
No test ? |
This comment has been minimized.
This comment has been minimized.
|
I have added a test. Thank you. |
|
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. |
There was a problem hiding this comment.
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.
|
Reminder, once the PR becomes ready for a review, use |
|
Oops, they are changes from early iterations and I forgot to change them back. |
|
@rustbot ready |
|
I undo irrelevant changes and change the error message to |
| 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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Or do you want the code to continue parse the tuple field and find every name field in map_err?
There was a problem hiding this comment.
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.
I close the previous PR because it's too messy
relevant issue:#144595
I fix this issue by calling
look_aheadto check if the user write a name field in the tuple struct, then try to recover after callingparse_ty