Skip to content

mbe: Rework the concat metavariable expression #142975

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

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Jun 24, 2025

#142950 plus followup

r? @ghost

tgross35 added 11 commits June 23, 2025 06:25
These tests have expanded beyond the RFC, so rename the directory
`rfc-3086-metavar-expr` to `metavar-expressions`. `concat` (which wasn't
part of the RFC) now fits in this group, so merge its tests into the
`metavar-expressions` directory.

Additionally rename some related `issue-*` tests.
`syntax-errors` currently contains both actual syntax error tests and
tests (which don't need expansion) and tests for incorrect usage of the
`count` metavariable expression (which dos need expansion). Split the
expansion-dependent tests to a separate file, remove unneeded
invocations from `syntax-errors` to ensure we are catching these before
expansion.
Add tests showing the current state to make it more clear when output
gets updated later in refactoring.
More diagnostic structs related to metavariable expressions will be
introduced. Introduce the abbreviation "mve" which is reasonably
unambiguous (`rg Mve` and `rg '(\b|_|-)mve(\b|_|-)'` return no results
outside of a Thumb target feature) and use it for these diagnostic
types. A new module is also created.
Move the `concat` implementation to a separate function so it is easier
to work on. Other metavariable expressions are already split this way.

This is a non-functional change.
Move this structure directly above the `parse_<expr>` functions that
return it to keep top-down flow.

This is a non-functional change.
The current messages have the potential to be more accurate; "expected
identifier or string literal" is printed in a few cases where only an
identifier should be expected, and it suggests removing string literals
when that might not solve the problem. Add a new diagnostic for these
kind of errors that gives some more context.

For `count` and `ignore` this should likely be combined with the
diagnositcs for `eat_dollar` to produce a helpful error if they get
anything other than a metavariable first argument. I am planning to do
this in a followup.
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.
* Now accept numbers, chars
* Suffixes are stripped (needs more testing)
* Report specific locations of errors
* TODO: handle idents the same for expanded tokens
@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 24, 2025
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Running eslint on rustdoc JS files
`rustdoc-json-types` was not modified.
No error code explanation was removed!
tidy: Skipping binary file check, read-only filesystem
##[error]tidy error: /checkout/compiler/rustc_expand/src/errors.rs:513: TODO is used for tasks that should be done before merging a PR; If you want to leave a message in the codebase use FIXME
##[error]tidy error: /checkout/tests/ui/macros/metavar-expressions/concat-allowed-operations.rs:122: TODO is used for tasks that should be done before merging a PR; If you want to leave a message in the codebase use FIXME
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'venv'
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'virtualenv'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (25.1.1)
linting python files
All checks passed!
checking python file formatting
28 files already formatted
checking C++ file formatting
some tidy checks failed
Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:01:24
  local time: Tue Jun 24 17:53:49 UTC 2025
  network time: Tue, 24 Jun 2025 17:53:49 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

@tgross35 tgross35 added the rla-silenced Silences rust-log-analyzer postings to the PR it's added on. label Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tidy Area: The tidy tool rla-silenced Silences rust-log-analyzer postings to the PR it's added on. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

3 participants