-
Notifications
You must be signed in to change notification settings - Fork 13.5k
mbe: Rework diagnostics for metavariable expressions #142950
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
base: master
Are you sure you want to change the base?
Conversation
There are changes to the cc @jieyouxu |
let Some(tt) = iter.next() else { | ||
let err = errors::MveExpectedIdent { span: fallback_span, not_ident_label: None, context }; | ||
return Err(psess.dcx().create_err(err)); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have mixed feelings about this, in general.
Now we take some typical parser errors, like "expected X, found Y", including "expected EOF, found Y" aka trailing tokens, and over-specialize them for the specific case of metavariable expressions.
Like for every "unexpected token" we create a separate "unexpected token ... in space!".
This is not scalable, parser code cannot be shared well if the errors are over-specialized.
For example, this specific change adds some specialized logic here, but leaves previously used parse_token
and parse_ident_from_token
unchanged.
If some improvements are made, they should go into parse_token
and be general enough to improve all users of that function, not some single specific case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a bit more context; I have continued work on top of these changes that eliminates parse_ident_from_token
and parse_token
for a more specific error 847b9f7 and then reuses the new logic for expansion diagnostics b576c49 (those two patches are a bit messy yet). The total diff was just getting a bit large so I put this PR up as a portion that can stand on its own without touching concat
too much. Created a draft with the (incomplete) rest just now #142975.
I'm happy to adjust the diagnostics further or break the PRs up differently if something else makes more sense to you. What would you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split the nonfunctional changes here to a new PR, #143245. I think this should make it a bit more straightforward to do the other changes here. |
…ation, r=petrochenkov mbe: Add tests and restructure metavariable expressions Add tests that show better diagnostics, and factor `concat` handling to a separate function. Each commit message has further details. This performs the nonfunctional perparation for further changes such as rust-lang#142950 and rust-lang#142975 .
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
Rollup merge of #143245 - tgross35:metavariable-expr-organization, r=petrochenkov mbe: Add tests and restructure metavariable expressions Add tests that show better diagnostics, and factor `concat` handling to a separate function. Each commit message has further details. This performs the nonfunctional perparation for further changes such as #142950 and #142975 .
☔ The latest upstream changes (presumably #143267) made this pull request unmergeable. Please resolve the merge conflicts. |
51693ef
to
1146773
Compare
This comment has been minimized.
This comment has been minimized.
1146773
to
391fc74
Compare
Give a more user-friendly diagnostic about the following: * Invalid syntax within the `${...}` braces, including missing parentheses or trailing tokens. * Incorrect number of arguments passed to specific metavariable expressions.
391fc74
to
13a7e49
Compare
Make the diagnostics for metavariable expressions more user-friendly. This mostly addresses syntactic errors; I will be following up with improvements to
concat(..)
.This is probably easiest to review by-commit, more details are in the messages.
r? @petrochenkov