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
Remove Nonterminal
and TokenKind::Interpolated
#124141
Draft
nnethercote
wants to merge
13
commits into
rust-lang:master
Choose a base branch
from
nnethercote:rm-Nonterminal-and-TokenKind-Interpolated
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Remove Nonterminal
and TokenKind::Interpolated
#124141
nnethercote
wants to merge
13
commits into
rust-lang:master
from
nnethercote:rm-Nonterminal-and-TokenKind-Interpolated
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
By using `token_descr`, as is done for many other errors, we can get slightly better descriptions in error messages, e.g. "macro expansion ignores token `let` and any following" becomes "macro expansion ignores keyword `let` and any tokens following". This will be more important once invisible delimiters start being mentioned in error messages.
It's not used meaningfully yet, but will be needed to get rid of interpolated tokens.
Pasted metavariables are wrapped in invisible delimiters, which pretty-print as empty strings, and changing that can break some proc macros. But error messages saying "expected identifer, found ``" are bad. So this commit adds support for metavariables in `TokenDescription` so they print as "metavariable" in error messages, instead of "``". It's not used meaningfully yet, but will be needed to get rid of interpolated tokens.
This has no effect right now because invisible delimiters aren't produced by `TokenCursor`, but it will make more sense once invisible delimiter origins are introduced.
rustbot
added
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.
labels
Apr 18, 2024
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
nnethercote
force-pushed
the
rm-Nonterminal-and-TokenKind-Interpolated
branch
from
April 19, 2024 05:24
632c374
to
42a623a
Compare
Current places where `Interpolated` is used are going to change to instead use invisible delimiters. This prepares for that by adding panics in various places.
We now use invisible delimiters for expanded `vis` fragments, instead of `Token::Interpolated`.
Notes about tests: - tests/ui/parser/macro/trait-object-macro-matcher.rs: the syntax error is duplicated, because it occurs now when parsing the decl macro input, and also when parsing the expanded decl macro. But this won't show up for normal users due to error de-duplication. - tests/ui/associated-consts/issue-93835.rs: ditto.
XXX: tests/ui/macros/trace_faulty_macros.rs regresses because I haven't fixed `expected_expression_found` properly yet.
This involves replacing `nt_pretty_printing_compatibility_hack` with `stream_pretty_printing_compatibility_hack`. The handling of statements in `transcribe` is slightly different to other nonterminal kinds, due to the lack of `from_ast` implementation for empty statements. Notable test changes: - `tests/ui/macros/nonterminal-matching.rs` now passes. Removal of `Token::Interpolated` will remove the "captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens" restriction. - `tests/ui/proc-macro/expand-to-derive.rs`: the diff looks large but the only difference is the insertion of a single invisible-delimited group. I hope this doesn't cause any new `ProceduralMasquerade`-type problems.
Note: there was an existing code path involving `Interpolated` in `MetaItem::from_tokens` that was dead. This commit transfers that to the new form, but puts an `unreachable!` call inside it.
Notes about tests: - tests/ui/macros/stringify.rs: the `c2` macro is no longer needed, because the TokenStream pretty printer is now used for all cases. - tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs: some messages are now duplicated due to repeated parsing. - tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions*.rs: ditto. Getting a test failure here: ``` Building tool error_index_generator (stage1 -> stage2, x86_64-unknown-linux-gnu) Compiling cfg-if v1.0.0 ... Compiling mdbook v0.4.37 error: internal compiler error: the following error was constructed but not emitted error: unexpected token: keyword `self` --> /home/njn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mdbook-0.4.37/src/book/summary.rs:280:31 | 280 | ... bail!(self.parse_error("Suffix chapters cannot be followed by a list")); | ^^^^ thread 'rustc' panicked at /home/njn/dev/rust3/compiler/rustc_errors/src/diagnostic.rs:1375:17: error was constructed but not emitted ```
nnethercote
force-pushed
the
rm-Nonterminal-and-TokenKind-Interpolated
branch
from
April 23, 2024 03:51
42a623a
to
c133e16
Compare
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
r? @ghost