about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
AgeCommit message (Collapse)AuthorLines
2025-08-02Auto merge of #129183 - estebank:cfg-visitor, r=davidtwcobors-2/+1
Detect more `cfg`d out items in resolution errors Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition. ``` error[E0425]: cannot find function `f` in this scope --> $DIR/nested-cfg-attrs.rs:4:13 | LL | fn main() { f() } | ^ not found in this scope | note: found an item that was configured out --> $DIR/nested-cfg-attrs.rs:2:4 | LL | fn f() {} | ^ note: the item is gated here --> $DIR/nested-cfg-attrs.rs:1:35 | LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))] | ^^^^^^^^^^ ```
2025-08-01tiny cleanupEsteban Küber-4/+2
2025-08-01remove recursive search for itemsEsteban Küber-33/+15
2025-08-01Limit how deep we visit items to find cfg'd out namesEsteban Küber-3/+12
2025-08-01Detect more `cfg`d out items in resolution errorsEsteban Küber-14/+24
Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition. ``` error[E0425]: cannot find function `f` in this scope --> $DIR/nested-cfg-attrs.rs:4:13 | LL | fn main() { f() } | ^ not found in this scope | note: found an item that was configured out --> $DIR/nested-cfg-attrs.rs:2:4 | LL | fn f() {} | ^ note: the item is gated here --> $DIR/nested-cfg-attrs.rs:1:35 | LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))] | ^^^^^^^^^^ ```
2025-07-31remove rustc_attr_data_structuresJana Dönszelmann-2/+4
2025-07-28Rollup merge of #143607 - JonathanBrouwer:proc_macro_attrs, ↵Matthias Krüger-152/+14
r=jdonszelmann,traviscross Port the proc macro attributes to the new attribute parsing infrastructure Ports `#[proc_macro]`, `#[proc_macro_attribute]`, `#[proc_macro_derive]` and `#[rustc_builtin_macro]` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971351163 I've split this PR into commits for reviewability, and left some comments to clarify things I did 4 related attributes in one PR because they share a lot of their code and logic, and doing them separately is kind of annoying as I need to leave both the old and new parsing in place then. r? ``@oli-obk`` cc ``@jdonszelmann``
2025-07-27split up define into define_extern and define_localLorrensP-2158466-1/+1
2025-07-26Remove now un-used codeJonathan Brouwer-140/+0
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-26Use the new attributes throughout the codebaseJonathan Brouwer-12/+14
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-25Stop compilation if macro expansion failedGuillaume Gomez-4/+13
2025-07-22mbe: Use concrete type for `get_unused_rule`Josh Triplett-14/+13
Rather than adding `get_unused_rule` to the `TTMacroExpander` trait, put it on the concrete `MacroRulesMacroExpander`, and downcast to that type via `Any` in order to call it. Suggested-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2025-07-18Rollup merge of #143925 - oli-obk:slice-const-partialeq, r=fee1-deadMatthias Krüger-2/+8
Make slice comparisons const This needed a fix for `derive_const`, too, as it wasn't usable in libcore anymore as trait impls need const stability attributes. I think we can't use the same system as normal trait impls while `const_trait_impl` is still unstable. r? ```@fee1-dead``` cc rust-lang/rust#143800
2025-07-17Make `derive_const` usable within libcore againOli Scherer-2/+8
Also make it *only* usable on nightly
2025-07-17Rollup merge of #143984 - JonathanBrouwer:fix-feature-gate-ice, r=UrgauMatthias Krüger-8/+18
Fix ice for feature-gated `cfg` attributes applied to the crate This PR fixes two fixes: 1. When a feature gated option of the `cfg` attribute is applied to the crate, an ICE would occur because features are not yet available at that stage. This is fixed by ignoring the feature gate at that point, the attribute will later be re-checked (this was already done) when the feature gate is available. Fixes https://github.com/rust-lang/rust/issues/143977 2. Errors and lints on the `cfg` attribute applied to the crate would be produced twice, because of the re-checking. This is fixed by not producing any errors and lints during the first run. The added regression test checks both problems. r? ``@jdonszelmann``
2025-07-17resolve: Change `&mut Resolver` to `&Resolver` when possibleVadim Petrochenkov-1/+1
2025-07-15Fix ice for feature-gated cfg attributes applied to the crateJonathan Brouwer-8/+18
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-15Define attribute parser & config evaluatorJonathan Brouwer-32/+58
2025-07-15Define datastructures for `#[cfg]` attribute, move StrippedCfgItemJonathan Brouwer-2/+8
2025-07-13Auto merge of #143461 - folkertdev:cfg-select-builtin-macro, r=petrochenkovbors-27/+58
make `cfg_select` a builtin macro tracking issue: https://github.com/rust-lang/rust/issues/115585 This parses mostly the same as the `macro cfg_select` version, except: 1. wrapping in double brackets is no longer supported (or needed): `cfg_select {{ /* ... */ }}` is now rejected. 2. in an expression context, the rhs is no longer wrapped in a block, so that this now works: ```rust fn main() { println!(cfg_select! { unix => { "foo" } _ => { "bar" } }); } ``` 3. a single wildcard rule is now supported: `cfg_select { _ => 1 }` now works I've also added an error if none of the rules evaluate to true, and warnings for any arms that follow the `_` wildcard rule. cc `@traviscross` if I'm missing any feature that should/should not be included r? `@petrochenkov` for the macro logic details
2025-07-13make `cfg_select` a builtin macroFolkert de Vries-27/+58
2025-07-09mbe: Refactor the diagnostic for unrecognized metavariable expressionsTrevor Gross-9/+15
Change to a structural diagnostic, update the valid list, and move the valid list to a note.
2025-07-09mbe: Refactor diagnostics for invalid metavar expression syntaxTrevor Gross-15/+103
Give a more user-friendly diagnostic about the following: * Trailing tokens within braces, e.g. `${foo() extra}` * Missing parentheses, e.g. `${foo}` * Incorrect number of arguments, with a hint about correct usage.
2025-07-06mbe: Clarify comments about error handling in `compile_declarative_macro`Josh Triplett-3/+2
2025-07-06mbe: Factor out a helper to check for unexpected EOF in definitionJosh Triplett-7/+14
Will get called additional times when expanding parsing to cover attributes
2025-07-06mbe: Factor out a helper to check an LHSJosh Triplett-2/+7
This currently gets called only once, but will get called multiple times when handling attributes.
2025-07-06mbe: Simplify compile_declarative_macro by factoring out some variablesJosh Triplett-11/+4
2025-07-05mbe: Defer checks for `compile_error!` until reporting an unused macro ruleJosh Triplett-73/+55
The MBE parser checks rules at initial parse time to see if their RHS has `compile_error!` in it, and returns a list of rule indexes and LHS spans that don't map to `compile_error!`, for use in unused macro rule checking. Instead, have the unused macro rule reporting ask the macro for the rule to report, and let the macro check at that time. That avoids checking rules unless they're unused. In the process, refactor the data structure used to store macro rules, to group the LHS and RHS (and LHS span) of each rule together, and refactor the unused rule tracking to only track rule indexes. This ends up being a net simplification, and reduction in code size.
2025-07-05mbe: Simplify a match to a let-elseJosh Triplett-3/+2
2025-07-05mbe: Add a helper to parse a single `TokenTree`Josh Triplett-22/+20
The parser repeatedly invokes the `parse` function, constructing a one-entry vector, and assuming that the return value will be a one-entry vector. Add a helper for that case. This will simplify adding additional callers, and put all the logic in one place to allow potential future simplification of the one-TT case.
2025-07-05mbe: Introduce an enum for which part of a rule we're parsingJosh Triplett-17/+36
Rather than a `bool` that's `true` for the LHS and `false` for the RHS, use a self-documenting enum.
2025-07-05Rollup merge of #143408 - joshtriplett:fix-mbe-parser, r=compiler-errorsMatthias Krüger-0/+9
mbe: Gracefully handle macro rules that end after `=>` Add a test for various cases of invalid macro definitions. Closes: https://github.com/rust-lang/rust/issues/143351
2025-07-03mbe: Gracefully handle macro rules that end after `=>`Josh Triplett-0/+9
Add a test for various cases of invalid macro definitions. Closes: https://github.com/rust-lang/rust/issues/143351
2025-07-04Rollup merge of #143380 - cjgillot:kw_span, r=compiler-errorsJacob Pratt-1/+1
Replace kw_span by full span for generic const parameters. Small simplification extracted from https://github.com/rust-lang/rust/pull/127241
2025-07-03Replace kw_span by full span.Camille GILLOT-1/+1
2025-07-03Rollup merge of #142876 - JonathanBrouwer:target_feature_parser, r=oli-obkJana Dönszelmann-1/+1
Port `#[target_feature]` to new attribute parsing infrastructure Ports `target_feature` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197 r? ``@jdonszelmann``
2025-07-03Rollup merge of #134006 - klensy:typos, r=nnethercoteJana Dönszelmann-1/+1
setup typos check in CI This allows to check typos in CI, currently for compiler only (to reduce commit size with fixes). With current setup, exclude list is quite short, so it worth trying? Also includes commits with actual typo fixes. MCP: https://github.com/rust-lang/compiler-team/issues/817 typos check currently turned for: * ./compiler * ./library * ./src/bootstrap * ./src/librustdoc After merging, PRs which enables checks for other crates (tools) can be implemented too. Found typos will **not break** other jobs immediately: (tests, building compiler for perf run). Job will be marked as red on completion in ~ 20 secs, so you will not forget to fix it whenever you want, before merging pr. Check typos: `python x.py test tidy --extra-checks=spellcheck` Apply typo fixes: `python x.py test tidy --extra-checks=spellcheck:fix` (in case if there only 1 suggestion of each typo) Current fail in this pr is expected and shows how typo errors emitted. Commit with error will be removed after r+.
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-07-03Port `#[target_feature]` to the new attribute parsing infrastructureJonathan Brouwer-1/+1
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-02Rollup merge of #143070 - joshtriplett:macro-rules-parse, r=petrochenkovMatthias Krüger-206/+61
Rewrite `macro_rules!` parser to not use the MBE engine itself The `macro_rules!` parser was written to match the series of rules using the macros-by-example (MBE) engine and a hand-written equivalent of the left-hand side of a MBE macro. This was complex to read, difficult to extend, and produced confusing error messages. Because it was using the MBE engine, any parse failure would be reported as if some macro was being applied to the `macro_rules!` invocation itself; for instance, errors would talk about "macro invocation", "macro arguments", and "macro call", when they were actually about the macro *definition*. And in practice, the `macro_rules!` parser only used the MBE engine to extract the left-hand side and right-hand side of each rule as a token tree, and then parsed the rest using a separate parser. Rewrite it to parse the series of rules using a simple loop, instead. This makes it more extensible in the future, and improves error messages. For instance, omitting a semicolon between rules will result in "expected `;`" and "unexpected token", rather than the confusing "no rules expected this token in macro call". This work was greatly aided by pair programming with Vincenzo Palazzo (`@vincenzopalazzo)` and Eric Holk (`@eholk).` For review, I recommend reading the two commits separately.
2025-07-02Rollup merge of #142237 - benschulz:unused-parens-fn, r=fee1-deadMatthias Krüger-0/+1
Detect more cases of unused_parens around types With this change, more unused parentheses around bounds and types nested within bounds are detected.
2025-07-01Detect more cases of unused_parens around typesBenjamin Schulz-0/+1
2025-07-01Auto merge of #143267 - matthiaskrgr:rollup-suvzar6, r=matthiaskrgrbors-60/+70
Rollup of 8 pull requests Successful merges: - rust-lang/rust#143125 (Disable f16 on Aarch64 without neon for llvm < 20.1.1) - rust-lang/rust#143156 (inherit `#[align]` from trait method prototypes) - rust-lang/rust#143178 (rustdoc default faviocon) - rust-lang/rust#143234 (Replace `ItemCtxt::report_placeholder_type_error` match with a call to `TyCtxt::def_descr`) - rust-lang/rust#143245 (mbe: Add tests and restructure metavariable expressions) - rust-lang/rust#143257 (Upgrade dependencies in run-make-support) - rust-lang/rust#143263 (linkify CodeSuggestion in doc comments) - rust-lang/rust#143264 (fix: Emit suggestion filename if primary diagnostic span is dummy) Failed merges: - rust-lang/rust#143251 (bootstrap: add build.tidy-extra-checks option) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-01Rollup merge of #143245 - tgross35:metavariable-expr-organization, ↵Matthias Krüger-60/+70
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: Move `MetaVarExprConcatElem` closer to where it is usedTrevor Gross-14/+14
Move this structure directly above the `parse_<expr>` functions that return it to keep top-down flow. This is a non-functional change.
2025-06-30mbe: Factor `concat` metavariable handling outTrevor Gross-40/+45
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.
2025-06-30mbe: Shorten `MetaVarExpr` -> `Mve` in structural diagnosticsTrevor Gross-10/+15
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-30Introduce `ByteSymbol`.Nicholas Nethercote-2/+6
It's like `Symbol` but for byte strings. The interner is now used for both `Symbol` and `ByteSymbol`. E.g. if you intern `"dog"` and `b"dog"` you'll get a `Symbol` and a `ByteSymbol` with the same index and the characters will only be stored once. The motivation for this is to eliminate the `Arc`s in `ast::LitKind`, to make `ast::LitKind` impl `Copy`, and to avoid the need to arena-allocate `ast::LitKind` in HIR. The latter change reduces peak memory by a non-trivial amount on literal-heavy benchmarks such as `deep-vector` and `tuple-stress`. `Encoder`, `Decoder`, `SpanEncoder`, and `SpanDecoder` all get some changes so that they can handle normal strings and byte strings. This change does slow down compilation of programs that use `include_bytes!` on large files, because the contents of those files are now interned (hashed). This makes `include_bytes!` more similar to `include_str!`, though `include_bytes!` contents still aren't escaped, and hashing is still much cheaper than escaping.
2025-06-26mbe: Fold calls to `check_meta_variables` into the parser loopJosh Triplett-18/+8
2025-06-26Rewrite `macro_rules!` parser to not use the MBE engine itselfJosh Triplett-188/+53
The `macro_rules!` parser was written to match the series of rules using the macros-by-example (MBE) engine and a hand-written equivalent of the left-hand side of a MBE macro. This was complex to read, difficult to extend, and produced confusing error messages. Because it was using the MBE engine, any parse failure would be reported as if some macro was being applied to the `macro_rules!` invocation itself; for instance, errors would talk about "macro invocation", "macro arguments", and "macro call", when they were actually about the macro *definition*. And in practice, the `macro_rules!` parser only used the MBE engine to extract the left-hand side and right-hand side of each rule as a token tree, and then parsed the rest using a separate parser. Rewrite it to parse the series of rules using a simple loop, instead. This makes it more extensible in the future, and improves error messages. For instance, omitting a semicolon between rules will result in "expected `;`" and "unexpected token", rather than the confusing "no rules expected this token in macro call". This work was greatly aided by pair programming with Vincenzo Palazzo and Eric Holk.