about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/mbe/transcribe.rs
AgeCommit message (Collapse)AuthorLines
2025-09-20mbe: Factor out a function to transcribe a `ParseNtResult`Josh Triplett-0/+8
2025-09-20mbe: Simplify match in `transcribe_metavar`Josh Triplett-18/+19
Factor out the check for a variable that's still repeating.
2025-09-14Move more early buffered lints to dyn lint diagnostics (1/N)León Orell Valerian Liehr-3/+3
2025-09-07support integer literals in `${concat()}`cyrgani-1/+17
2025-09-01Add compiler error when trying to use concat metavar expr in repetitionsjullang-1/+6
Replace unimplemented()! with a more helpful compiler error.
2025-07-01Rollup merge of #143245 - tgross35:metavariable-expr-organization, ↵Matthias Krüger-2/+2
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 https://github.com/rust-lang/rust/pull/142950 and https://github.com/rust-lang/rust/pull/142975 .
2025-06-30mbe: Shorten `MetaVarExpr` -> `Mve` in structural diagnosticsTrevor Gross-2/+2
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.
2025-06-24Rollup merge of #142657 - tgross35:nonoptional-fragment-specifiers-cleanup, ↵Matthias Krüger-2/+2
r=petrochenkov mbe: Clean up code with non-optional `NonterminalKind` Since [rust-lang/rust#128425], the fragment specifier is unconditionally required in all editions. This means `NonTerminalKind` no longer needs to be optional, as we can reject this code during the expansion of `macro_rules!` rather than handling it throughout the code. Do this cleanup here. [rust-lang/rust#128425]: https://github.com/rust-lang/rust/pull/128425
2025-06-24mbe: Clean up code with non-optional `NonterminalKind`Trevor Gross-2/+2
Since [1], the fragment specifier is unconditionally required in all editions. This means `NonTerminalKind` no longer needs to be optional, as we can reject this code during the expansion of `macro_rules!` rather than handling it throughout the code. Do this cleanup here. [1]: https://github.com/rust-lang/rust/pull/128425
2025-06-19mbe: Refactor transcriptionTrevor Gross-348/+389
Introduce `MacroTcbCtx` that holds everything relevant to transcription. This allows for the following changes: * Split `transcribe_sequence` and `transcribe_metavar` out of the heavily nested `transcribe` * Split `metavar_expr_concat` out of `transcribe_metavar_expr` This is a nonfunctional change.
2025-06-19mbe: Move `transcribe_metavar_expr` directly after `transcribe`Trevor Gross-96/+96
Be more consistent with the otherwise top-down organization of this file.
2025-04-30ast: Remove token visiting from AST visitorVadim Petrochenkov-16/+16
It's no longer necessary after the removal of nonterminal tokens in #124141.
2025-04-02Impl `Copy` for `Token` and `TokenKind`.Nicholas Nethercote-2/+2
2025-04-02Remove `NtBlock`, `Nonterminal`, and `TokenKind::Interpolated`.Nicholas Nethercote-11/+8
`NtBlock` is the last remaining variant of `Nonterminal`, so once it is gone then `Nonterminal` can be removed as well.
2025-04-02Remove `NtExpr` and `NtLiteral`.Nicholas Nethercote-7/+28
Notes about tests: - 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. - `tests/ui/proc-macro/macro-rules-derive-cfg.rs`: the diff looks large but the only difference is the insertion of a single invisible-delimited group around a metavar. - `tests/ui/attributes/nonterminal-expansion.rs`: a slight span degradation, somehow related to the recent massive attr parsing rewrite (#135726). I couldn't work out exactly what is going wrong, but I don't think it's worth holding things up for a single slightly suboptimal error message.
2025-03-07Remove `NtItem` and `NtStmt`.Nicholas Nethercote-1/+13
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/proc-macro/expand-to-derive.rs`: the diff looks large but the only difference is the insertion of a single invisible-delimited group around a metavar.
2025-02-28Remove `NtPath`.Nicholas Nethercote-0/+3
2025-02-28Remove `NtMeta`.Nicholas Nethercote-0/+8
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.
2025-02-28Remove `NtPat`.Nicholas Nethercote-4/+14
The one notable test change is `tests/ui/macros/trace_faulty_macros.rs`. This commit removes the complicated `Interpolated` handling in `expected_expression_found` that results in a longer error message. But I think the new, shorter message is actually an improvement. The original complaint was in #71039, when the error message started with "error: expected expression, found `1 + 1`". That was confusing because `1 + 1` is an expression. Other than that, the reporter said "the whole error message is not too bad if you ignore the first line". Subsequently, extra complexity and wording was added to the error message. But I don't think the extra wording actually helps all that much. In particular, it still says of the `1+1` that "this is expected to be expression". This repeats the problem from the original complaint! This commit removes the extra complexity, reverting to a simpler error message. This is primarily because the traversal is a pain without `Interpolated` tokens. Nonetheless, I think the error message is *improved*. It now starts with "expected expression, found `pat` metavariable", which is much clearer and the real problem. It also doesn't say anything specific about `1+1`, which is good, because the `1+1` isn't really relevant to the error -- it's the `$e:pat` that's important.
2025-02-22Rollup merge of #137333 - compiler-errors:edition-2024-fresh, r=NadrierilMatthias Krüger-2/+2
Use `edition = "2024"` in the compiler (redux) Most of this is binding mode changes, which I fixed by running `x.py fix`. Also adds some miscellaneous `unsafe` blocks for new unsafe standard library functions (the setenv ones), and a missing `unsafe extern` block in some enzyme codegen code, and fixes some precise capturing lifetime changes (but only when they led to errors). cc ``@ehuss`` ``@traviscross``
2025-02-22Fix binding mode problemsMichael Goulet-2/+2
2025-02-21Avoid snapshotting the parser in `parse_path_inner`.Nicholas Nethercote-2/+3
2025-02-21Remove `NtTy`.Nicholas Nethercote-0/+3
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: similar, plus there are some additional errors about this very broken code. - The changes to metavariable descriptions in #132629 are now visible in error message for several tests.
2025-02-21Remove `NtVis`.Nicholas Nethercote-1/+34
We now use invisible delimiters for expanded `vis` fragments, instead of `Token::Interpolated`.
2025-02-03tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`Askar Safin-2/+2
2025-01-22Auto merge of #134478 - compiler-errors:attr-span, r=oli-obkbors-10/+10
Properly record metavar spans for other expansions other than TT This properly records metavar spans for nonterminals other than tokentree. This means that we operations like `span.to(other_span)` work correctly for macros. As you can see, other diagnostics involving metavars have improved as a result. Fixes #132908 Alternative to #133270 cc `@ehuss` cc `@petrochenkov`
2024-12-26Rollup merge of #131522 - c410-f3r:unlock-rfc-2011, r=chenyukangJacob Pratt-2/+4
[macro_metavar_expr_concat] Fix #128346 Fix #128346 Fix #131393 The syntax is invalid in both issues so I guess that theoretically the compiler should have aborted early. This PR tries to fix a local problem but let me know if there are better options. cc `@petrochenkov` if you are interested
2024-12-21Hash only the spans that we care ended up reading in Span::try_metavarsMichael Goulet-17/+12
2024-12-21Hash the untracked macro variable expansionsMichael Goulet-9/+10
2024-12-21Properly record metavar spans for other expansions other than TTMichael Goulet-0/+4
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+3
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-01Fix #128346Caio-2/+4
2024-10-28fix clippy::clone_on_ref_ptr for compilerklensy-1/+2
2024-10-23"innermost", "outermost", "leftmost", and "rightmost" don't need hyphensJosh Triplett-1/+1
These are all standard dictionary words and don't require hyphenation.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-5/+5
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-8/+8
2024-09-06Add initial support for raw lifetimesMichael Goulet-2/+2
2024-07-29Reformat `use` declarations.Nicholas Nethercote-12/+13
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-22Always pass the visitor as the first argument to walk* functionsOli Scherer-2/+2
2024-07-19Allow concat in repetitionsCaio-37/+56
2024-07-17Add support for literalsCaio-24/+35
2024-07-06Add support for literalsCaio-5/+27
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-6/+6
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-18Prefer `dcx` methods over fields or fields' methodsOli Scherer-1/+1
2024-06-15Rollup merge of #125829 - petrochenkov:upctxt2, r=michaelwoeristerMatthias Krüger-1/+1
rustc_span: Add conveniences for working with span formats This is the refactoring part of https://github.com/rust-lang/rust/pull/125017.
2024-06-13Add a new concat metavar exprCaio-3/+51
2024-06-13rustc_span: By-value interface for ctxt updateVadim Petrochenkov-1/+1
2024-06-10rustc_span: Optimize syntax context updates in spansVadim Petrochenkov-5/+5
2024-05-28Remove a stray comment that shouldn't be here.Nicholas Nethercote-1/+0
2024-05-27Rollup merge of #125530 - SparrowLii:expand2, r=petrochenkovGuillaume Gomez-31/+29
cleanup dependence of `ExtCtxt` in transcribe when macro expansion part of #125356 We can remove `transcribe`’s dependence on `ExtCtxt` to facilitate subsequent work (such as moving macro expansion into the incremental compilation system) r? ```@petrochenkov``` Thanks for the reviewing!