about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2025-07-22mbe: Use concrete type for `get_unused_rule`Josh Triplett-1/+1
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-06-12Introduce `-Zmacro-stats`.Nicholas Nethercote-0/+1
It collects data about macro expansions and prints them in a table after expansion finishes. It's very useful for detecting macro bloat, especially for proc macros. Details: - It measures code snippets by pretty-printing them and then measuring lines and bytes. This required a bunch of additional pretty-printing plumbing, in `rustc_ast_pretty` and `rustc_expand`. - The measurement is done in `MacroExpander::expand_invoc`. - The measurements are stored in `ExtCtxt::macro_stats`.
2025-06-08Remove all unused feature gates from the compilerbjorn3-1/+0
2025-05-27Do not get proc_macro from the sysroot in rustcbjorn3-2/+0
With the stage0 refactor the proc_macro version found in the sysroot will no longer always match the proc_macro version that proc-macros get compiled with by the rustc executable that uses this proc_macro. This will cause problems as soon as the ABI of the bridge gets changed to implement new features or change the way existing features work. To fix this, this commit changes rustc crates to depend directly on the local version of proc_macro which will also be used in the sysroot that rustc will build.
2025-05-12update cfg(bootstrap)Pietro Albini-1/+0
2025-04-23Make #![feature(let_chains)] bootstrap conditional in compiler/est31-1/+1
2025-03-11Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-10Revert "Use workspace lints for crates in `compiler/` #138084"许杰友 Jieyou Xu (Joe)-0/+1
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to consider options that avoids breaking downstream usages of cargo on distributed `rustc-src` artifacts, where such cargo invocations fail due to inability to inherit `lints` from workspace root manifest's `workspace.lints` (this is only valid for the source rust-lang/rust workspace, but not really the distributed `rustc-src` artifacts). This breakage was reported in <https://github.com/rust-lang/rust/issues/138304>. This reverts commit 48caf81484b50dca5a5cebb614899a3df81ca898, reversing changes made to c6662879b27f5161e95f39395e3c9513a7b97028.
2025-03-08Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
(Except for `rustc_codegen_cranelift`.) It's no longer necessary now that `unreachable_pub` is in the workspace lints.
2024-08-27Add `warn(unreachable_pub)` to `rustc_expand`.Nicholas Nethercote-0/+1
Plus a tiny bit of reformatting.
2024-05-06Move some tests from `rustc_expand` to `rustc_parse`.Nicholas Nethercote-20/+0
There are some test cases involving `parse` and `tokenstream` and `mut_visit` that are located in `rustc_expand`. Because it used to be the case that constructing a `ParseSess` required the involvement of `rustc_expand`. However, since #64197 merged (a long time ago) `rust_expand` no longer needs to be involved. This commit moves the tests into `rustc_parse`. This is the optimal place for the `parse` tests. It's not ideal for the `tokenstream` and `mut_visit` tests -- they would be better in `rustc_ast` -- but they still rely on parsing, which is not available in `rustc_ast`. But `rustc_parse` is lower down in the crate graph and closer to `rustc_ast` than `rust_expand`, so it's still an improvement for them. The exact renaming is as follows: - rustc_expand/src/mut_visit/tests.rs -> rustc_parse/src/parser/mut_visit/tests.rs - rustc_expand/src/tokenstream/tests.rs -> rustc_parse/src/parser/tokenstream/tests.rs - rustc_expand/src/tests.rs + rustc_expand/src/parse/tests.rs -> compiler/rustc_parse/src/parser/tests.rs The latter two test files are combined because there's no need for them to be separate, and having a `rustc_parse::parser::parse` module would be weird. This also means some `pub(crate)`s can be removed.
2024-05-03De-`pub` some `rustc_expand` modules.Nicholas Nethercote-7/+5
2024-05-03Remove an unnecessary `#[macro_use]`.Nicholas Nethercote-1/+0
2024-05-03Remove an unnecessary re-export of `rustc_span::hygiene`.Nicholas Nethercote-1/+0
2024-05-03rustc_expand: clean up attributes.Nicholas Nethercote-5/+5
Sort them, and remove the unused ones (`lint_reasons` and `proc_macro_span`).
2024-05-01Step bootstrap cfgsMark Rousskov-1/+0
2024-04-30Remove `extern crate tracing` from numerous crates.Nicholas Nethercote-3/+0
2024-04-29Remove `extern crate rustc_macros` from numerous crates.Nicholas Nethercote-3/+0
2024-03-20Rollup merge of #122540 - WaffleLapkin:ununexpected, r=estebankMatthias Krüger-0/+1
Do not use `?`-induced skewing of type inference in the compiler This prevents breakage from #122412 and is generally a good idea. r? `@estebank`
2024-03-15Use `do yeet ()` and `do yeet _` instead of `None?` and `Err(_)?` in compilerMaybe Waffle-0/+1
This prevents breakage when `?` no longer skews inference.
2024-03-08Stabilize associated type boundsMichael Goulet-1/+1
2024-03-06Rewrite the `untranslatable_diagnostic` lint.Nicholas Nethercote-0/+1
Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This commit changes it to check calls to any function with an `impl Into<{D,Subd}iagMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. The commit also adds `#[allow(rustc::untranslatable_diagnostic)`] attributes to places that need it that are caught by the improved lint. These places that might be easy to convert to translatable diagnostics. Finally, it also: - Expands and corrects some comments. - Does some minor formatting improvements. - Adds missing `DecorateLint` cases to `tests/ui-fulldeps/internal-lints/diagnostics.rs`.
2024-02-18macro_rules: Preserve all metavariable spans in a global side tableVadim Petrochenkov-0/+1
2024-02-06Invert diagnostic lints.Nicholas Nethercote-1/+1
That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.
2024-01-25Remove unused featuresclubby789-2/+0
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-3/+1
Currently we always do this: ``` use rustc_fluent_macro::fluent_messages; ... fluent_messages! { "./example.ftl" } ``` But there is no need, we can just do this everywhere: ``` rustc_fluent_macro::fluent_messages! { "./example.ftl" } ``` which is shorter.
2023-11-26Avoid need for `{D,Subd}iagnosticMessage` imports.Nicholas Nethercote-1/+0
The `fluent_messages!` macro produces uses of `crate::{D,Subd}iagnosticMessage`, which means that every crate using the macro must have this import: ``` use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; ``` This commit changes the macro to instead use `rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the imports.
2023-11-15Bump cfg(bootstrap)sMark Rousskov-2/+2
2023-10-16docs: add Rust logo to more compiler cratesMichael Howell-0/+2
c6e6ecb1afea9695a42d0f148ce153536b279eb5 added it to some of the compiler's crates, but avoided adding it to all of them to reduce bit-rot. This commit adds to more.
2023-08-23Bump cfg(bootstrap)Mark Rousskov-1/+1
2023-08-03Add `internal_features` lintNilstrieb-0/+1
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-04-18Add `rustc_fluent_macro` to decouple fluent from `rustc_macros`Nilstrieb-1/+1
Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).
2023-03-11Simplify message pathsest31-1/+1
This makes it easier to open the messages file while developing on features. The commit was the result of automatted changes: for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done
2023-02-22errors: generate typed identifiers in each crateDavid Wood-0/+5
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2022-12-10Migrate parts of `rustc_expand` to session diagnosticsnils-0/+6
This migrates everything but the `mbe` and `proc_macro` modules. It also contains a few cleanups and drive-by/accidental diagnostic improvements which can be seen in the diff for the UI tests.
2022-09-26remove cfg(bootstrap)Pietro Albini-1/+0
2022-09-15Only enable the let_else feature on bootstrapest31-1/+1
On later stages, the feature is already stable. Result of running: rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-0/+3
by module
2022-08-29Revert let_chains stabilizationNilstrieb-0/+1
This reverts commit 326646074940222d602f3683d0559088690830f4. This is the revert against master, the beta revert was already done in #100538.
2022-08-17Moved structs to rustc_expand::errors, added several more migrations, fixed ↵nidnogg-0/+1
slug name
2022-08-12Adjust cfgsMark Rousskov-1/+0
2022-07-23Auto merge of #99320 - NiklasJonsson:84447/rustc_expand, r=compiler-errorsbors-1/+0
rustc_expand: Switch FxHashMap to FxIndexMap where iteration is used Relates #84447
2022-07-16Stabilize `let_chains`Caio-1/+1
2022-07-16rustc_expand: Switch FxHashMap to FxIndexMap where iteration is usedNiklas Jonsson-1/+0
2022-06-27various: add `rustc_lint_diagnostics` to diag fnsDavid Wood-0/+1
The `rustc_lint_diagnostics` attribute is used by the diagnostic translation/struct migration lints to identify calls where non-translatable diagnostics or diagnostics outwith impls are being created. Any function used in creating a diagnostic should be annotated with this attribute so this commit adds the attribute to many more functions. Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-09Never regard macro rules with compile_error! invocations as unusedest31-0/+1
The very point of compile_error! is to never be reached, and one of the use cases of the macro, currently also listed as examples in the documentation of compile_error, is to create nicer errors for wrong macro invocations. Thus, we shuuld never warn about unused macro arms that contain invocations of compile_error.
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-3/+2
2022-04-08Left overs of #95761Caio-1/+0
2022-04-07Kickstart the inner usage of macro_metavar_exprCaio-1/+2
2022-04-04A new matcher representation for use in `parse_tt`.Nicholas Nethercote-2/+0
`parse_tt` currently traverses a `&[TokenTree]` to do matching. But this is a bad representation for the traversal. - `TokenTree` is nested, and there's a bunch of expensive and fiddly state required to handle entering and exiting nested submatchers. - There are three positions (sequence separators, sequence Kleene ops, and end of the matcher) that are represented by an index that exceeds the end of the `&[TokenTree]`, which is clumsy and error-prone. This commit introduces a new representation called `MatcherLoc` that is designed specifically for matching. It fixes all the above problems, making the code much easier to read. A `&[TokenTree]` is converted to a `&[MatcherLoc]` before matching begins. Despite the cost of the conversion, it's still a net performance win, because various pieces of traversal state are computed once up-front, rather than having to be recomputed repeatedly during the macro matching. Some improvements worth noting. - `parse_tt_inner` is *much* easier to read. No more having to compare `idx` against `len` and read comments to understand what the result means. - The handling of `Delimited` in `parse_tt_inner` is now trivial. - The three end-of-sequence cases in `parse_tt_inner` are now handled in three separate match arms, and the control flow is much simpler. - `nameize` is no longer recursive. - There were two places that issued "missing fragment specifier" errors: one in `parse_tt_inner()`, and one in `nameize()`. Presumably the latter was never executed. There's now a single place issuing these errors, in `compute_locs()`. - The number of heap allocations done for a `check full` build of `async-std-1.10.0` (an extreme example of heavy macro use) drops from 11.8M to 2.6M, and most of these occur outside of macro matching. - The size of `MatcherPos` drops from 64 bytes to 16 bytes. Small enough that it no longer needs boxing, which partly accounts for the reduction in allocations. - The rest of the drop in allocations is due to the removal of `MatcherKind`, because we no longer need to record anything for the parent matcher when entering a submatcher. - Overall it reduces code size by 45 lines.