about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros
AgeCommit message (Collapse)AuthorLines
2025-09-29Use `Iterator::eq` and (dogfood) `eq_by` in compiler and libraryYotam Ofek-14/+7
2025-09-25Rollup merge of #146766 - nikic:global-alloc-attr, r=nnethercoteStuart Cook-3/+13
Add attributes for #[global_allocator] functions Emit `#[rustc_allocator]` etc. attributes on the functions generated by the `#[global_allocator]` macro, which will emit LLVM attributes like `"alloc-family"`. If the module with the global allocator participates in LTO, this ensures that the attributes typically emitted on the allocator declarations are not lost if the definition is imported. There is a similar issue when the allocator shim is used, but I've opted not to fix that case in this PR, because doing that cleanly is somewhat gnarly. Related to https://github.com/rust-lang/rust/issues/145995.
2025-09-23Add attributes for #[global_allocator] functionsNikita Popov-3/+13
Emit `#[rustc_allocator]` etc. attributes on the functions generated by the `#[global_allocator]` macro, which will emit LLVM attributes like `"alloc-family"`. If the module with the global allocator participates in LTO, this ensures that the attributes typically emitted on the allocator declarations are not lost if the definition is imported.
2025-09-21Add panic=immediate-abortBen Kimock-6/+4
2025-09-17Rollup merge of #146598 - bjorn3:feature_llvm_enzyme, r=davidtwcoJana Dönszelmann-1/+7
Make llvm_enzyme a regular cargo feature This makes it clearer that it is set by the build system rather than by the rustc that compiles the current rustc. It also avoids bootstrap needing to pass `--check-cfg llvm_enzyme` to rustc.
2025-09-16Rollup merge of #145095 - tiif:unstable_const_param, r=BoxyUwUStuart Cook-40/+0
Migrate `UnsizedConstParamTy` to unstable impl of `ConstParamTy_` Now that we have ``#[unstable_feature_bound]``, we can remove ``UnsizedConstParamTy`` that was meant to be an unstable impl of stable type and ``ConstParamTy_`` trait. r? `@BoxyUwU`
2025-09-15Make llvm_enzyme a regular cargo featurebjorn3-1/+7
This makes it clearer that it is set by the build system rather than by the rustc that compiles the current rustc. It also avoids bootstrap needing to pass --check-cfg llvm_enzyme to rustc.
2025-09-15Remove UnsizedConstParamTy trait and make it into an unstable impltiif-40/+0
2025-09-14Move more early buffered lints to dyn lint diagnostics (1/N)León Orell Valerian Liehr-10/+37
2025-09-12Use raw fmt str in format macroIoaNNUwU-4/+10
2025-09-11Revert "Rollup merge of #122661 - estebank:assert-macro-span, r=petrochenkov"Jieyou Xu-21/+14
This reverts commit 1eeb8e8b151d1da7daa73837a25dc5f7a1a7fa28, reversing changes made to 324bf2b9fd8bf9661e7045c8a93f5ff0ec1a8ca5. Unfortunately the assert desugaring change is not backwards compatible, see RUST-145770. Code such as ```rust #[derive(Debug)] struct F { data: bool } impl std::ops::Not for F { type Output = bool; fn not(self) -> Self::Output { !self.data } } fn main() { let f = F { data: true }; assert!(f); } ``` would be broken by the assert desugaring change. We may need to land the change over an edition boundary, or limit the editions that the desugaring change impacts.
2025-09-10Rollup merge of #146340 - fmease:frontmatter-containment, r=fee1-dead,UrgauMatthias Krüger-38/+62
Strip frontmatter in fewer places * Stop stripping frontmatter in `proc_macro::Literal::from_str` (RUST-146132) * Stop stripping frontmatter in expr-ctxt (but not item-ctxt!) `include`s (RUST-145945) * Stop stripping shebang (!) in `proc_macro::Literal::from_str` * Not a breaking change because it did compare spans already to ensure there wasn't extra whitespace or comments (`Literal::from_str("#!\n0")` already yields `Err(_)` thankfully!) * Stop stripping frontmatter+shebang inside some rustdoc code where it doesn't make any observable difference (see self review comments) * (Stop stripping frontmatter+shebang inside internal test code) Fixes https://github.com/rust-lang/rust/issues/145945. Fixes https://github.com/rust-lang/rust/issues/146132. r? fee1-dead
2025-09-09Strip frontmatter in fewer placesLeón Orell Valerian Liehr-25/+44
2025-09-09Improve docs of certain built-in macro expandersLeón Orell Valerian Liehr-13/+18
2025-09-08Apply requested changesIoaNNUwU-29/+15
2025-09-08Implement better suggestions based on additional tests and other code pathsIoaNNUwU-20/+38
2025-09-08Suggest examples of format specifiers in error messagesIoaNNUwU-2/+25
2025-09-02Revert introduction of `[workspace.dependencies]`.Nicholas Nethercote-2/+2
This was done in #145740 and #145947. It is causing problems for people using r-a on anything that uses the rustc-dev rustup package, e.g. Miri, clippy. This repository has lots of submodules and subtrees and various different projects are carved out of pieces of it. It seems like `[workspace.dependencies]` will just be more trouble than it's worth.
2025-08-27Rollup merge of #145905 - TaKO8Ki:fix-137580, r=nnethercoteMatthias Krüger-1/+1
Stop calling unwrap when format foreign has trailing dollar Fixes rust-lang/rust#137580
2025-08-27Add `tracing` to `[workspace.dependencies]`.Nicholas Nethercote-1/+1
2025-08-27Add `thin-vec` to newly added `[workspace.dependencies]`.Nicholas Nethercote-1/+1
2025-08-27stop returning errors when format foreign has trailing dollarTakayuki Maeda-1/+1
2025-08-22Rollup merge of #145747 - joshtriplett:builtin-diag-dyn, r=jdonszelmannJacob Pratt-3/+5
Refactor lint buffering to avoid requiring a giant enum Lint buffering currently relies on a giant enum `BuiltinLintDiag` containing all the lints that might potentially get buffered. In addition to being an unwieldy enum in a central crate, this also makes `rustc_lint_defs` a build bottleneck: it depends on various types from various crates (with a steady pressure to add more), and many crates depend on it. Having all of these variants in a separate crate also prevents detecting when a variant becomes unused, which we can do with a dedicated type defined and used in the same crate. Refactor this to use a dyn trait, to allow using `LintDiagnostic` types directly. Because the existing `BuiltinLintDiag` requires some additional types in order to decorate some variants, which are only available later in `rustc_lint`, use an enum `DecorateDiagCompat` to handle both the `dyn LintDiagnostic` case and the `BuiltinLintDiag` case. --- With the infrastructure in place, use it to migrate three of the enum variants to use `LintDiagnostic` directly, as a proof of concept and to demonstrate that the net result is a reduction in code size and a removal of a boilerplate-heavy layer of indirection. Also remove an unused `BuiltinLintDiag` variant.
2025-08-22Refactor lint buffering to avoid requiring a giant enumJosh Triplett-3/+5
Lint buffering currently relies on a giant enum `BuiltinLintDiag` containing all the lints that might potentially get buffered. In addition to being an unwieldy enum in a central crate, this also makes `rustc_lint_defs` a build bottleneck: it depends on various types from various crates (with a steady pressure to add more), and many crates depend on it. Having all of these variants in a separate crate also prevents detecting when a variant becomes unused, which we can do with a dedicated type defined and used in the same crate. Refactor this to use a dyn trait, to allow using `LintDiagnostic` types directly. This requires boxing, but all of this is already on the slow path (emitting an error). Because the existing `BuiltinLintDiag` requires some additional types in order to decorate some variants, which are only available later in `rustc_lint`, use an enum `DecorateDiagCompat` to handle both the `dyn LintDiagnostic` case and the `BuiltinLintDiag` case.
2025-08-22Move validate_attr to `rustc_attr_parsing`Jonathan Brouwer-3/+4
2025-08-21Rollup merge of #145590 - nnethercote:ModKind-Inline, r=petrochenkovJacob Pratt-1/+1
Prevent impossible combinations in `ast::ModKind`. `ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`. This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`. r? ```@Urgau```
2025-08-19Auto merge of #145601 - jieyouxu:rollup-t5mbqhc, r=jieyouxubors-35/+36
Rollup of 10 pull requests Successful merges: - rust-lang/rust#145538 (bufreader::Buffer::backshift: don't move the uninit bytes) - rust-lang/rust#145542 (triagebot: Don't warn no-mentions on subtree updates) - rust-lang/rust#145549 (Update rust maintainers in openharmony.md) - rust-lang/rust#145550 (Avoid using `()` in `derive(From)` output.) - rust-lang/rust#145556 (Allow stability attributes on extern crates) - rust-lang/rust#145560 (Remove unused `PartialOrd`/`Ord` from bootstrap) - rust-lang/rust#145568 (ignore frontmatters in `TokenStream::new`) - rust-lang/rust#145571 (remove myself from some adhoc-groups and pings) - rust-lang/rust#145576 (Add change tracker entry for `--timings`) - rust-lang/rust#145578 (Add VEXos "linked files" support to `armv7a-vex-v5`) r? `@ghost` `@rustbot` modify labels: rollup
2025-08-19Prevent impossible combinations in `ast::ModKind`.Nicholas Nethercote-1/+1
`ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`. This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`.
2025-08-19Rollup merge of #145429 - bjorn3:codegen_fn_attrs_improvements, r=jdonszelmann许杰友 Jieyou Xu (Joe)-1/+0
Couple of codegen_fn_attrs improvements As noted in https://github.com/rust-lang/rust/pull/144678#discussion_r2245060329 here is no need to keep link_name and export_name separate, which the third commit fixes by merging them. The second commit removes some dead code and the first commit merges two ifs with equivalent conditions. The last commit is an unrelated change which removes an unused `feature(autodiff)`.
2025-08-19Avoid using `()` in `derive(From)` output.Nicholas Nethercote-35/+36
Using an error type instead of `()` avoids the duplicated errors on `struct SUnsizedField` in `deriving-from-wrong-target.rs`. It also improves the expanded output from this: ``` struct S2(u32, u32); impl ::core::convert::From<()> for S2 { #[inline] fn from(value: ()) -> S2 { (/*ERROR*/) } } ``` to this: ``` struct S2(u32, u32); impl ::core::convert::From<(/*ERROR*/)> for S2 { #[inline] fn from(value: (/*ERROR*/)) -> S2 { (/*ERROR*/) } } ``` The new code also only matchs on `item.kind` once.
2025-08-15Rollup merge of #144922 - Kobzol:derive-from, r=nnethercoteJacob Pratt-2/+170
Implement `#[derive(From)]` Implements the `#[derive(From)]` feature ([tracking issue](https://github.com/rust-lang/rust/issues/144889), [RFC](https://github.com/rust-lang/rfcs/pull/3809)). It allows deriving the `From` impl on structs and tuple structs with exactly one field. Some implementation notes: - I wasn't exactly sure which spans to use in the derive generating code, so I just used `span` everywhere. I don't know if it's the Right Thing To Do. In particular the errors when `#[derive(From)]` is used on a struct with an unsized field are weirdly duplicated. - I had to solve an import stability problem, where if I just added the unstable `macro From` to `core::convert`, previously working code like `use std::convert::From` would suddenly require an unstable feature gate, because rustc would think that you're trying to import the unstable macro. `@petrochenkov` suggested that I add the macro the the core prelude instead. This has worked well, although it only works in edition 2021+. Not sure if I botched the prelude somehow and it should live elsewhere (?). - I had to add `Ty::AstTy`, because the `from` function receives an argument with the type of the single field, and the existing variants of the `Ty` enum couldn't represent an arbitrary type.
2025-08-15Implement `#[derive(From)]`Jakub Beránek-5/+158
2025-08-15Create unstable `From` builtin macro and register itJakub Beránek-0/+15
2025-08-15Remove unused feature gatebjorn3-1/+0
2025-08-15Rollup merge of #142640 - Sa4dUs:ad-intrinsic, r=ZuseZ4Stuart Cook-305/+130
Implement autodiff using intrinsics This PR aims to move autodiff logic to `autodiff` intrinsic. Allowing us to delete a great part of our frontend code and overall, simplify the compilation pipeline of autodiff functions.
2025-08-15Rollup merge of #122661 - estebank:assert-macro-span, r=petrochenkovStuart Cook-14/+21
Change the desugaring of `assert!` for better error output In the desugaring of `assert!`, we now expand to a `match` expression instead of `if !cond {..}`. The span of incorrect conditions will point only at the expression, and not the whole `assert!` invocation. ``` error[E0308]: mismatched types --> $DIR/issue-14091.rs:2:13 | LL | assert!(1,1); | ^ expected `bool`, found integer ``` We no longer mention the expression needing to implement the `Not` trait. ``` error[E0308]: mismatched types --> $DIR/issue-14091-2.rs:15:13 | LL | assert!(x, x); | ^ expected `bool`, found `BytePos` ``` Now `assert!(val)` desugars to: ```rust match val { true => {}, _ => $crate::panic::panic_2021!(), } ``` Fix #122159.
2025-08-14Remove inlining for autodiff handlingMarcelo Domínguez-12/+20
2025-08-14Complete functionality and general cleanupMarcelo Domínguez-401/+91
2025-08-14Basic implementation of `autodiff` intrinsicMarcelo Domínguez-6/+133
2025-08-14Remove the old target checking logicJonathan Brouwer-16/+1
2025-08-12Change the desugaring of `assert!` for better error outputEsteban Küber-14/+21
In the desugaring of `assert!`, we now expand to a `match` expression instead of `if !cond {..}`. The span of incorrect conditions will point only at the expression, and not the whole `assert!` invocation. ``` error[E0308]: mismatched types --> $DIR/issue-14091.rs:2:13 | LL | assert!(1,1); | ^ expected `bool`, found integer ``` We no longer mention the expression needing to implement the `Not` trait. ``` error[E0308]: mismatched types --> $DIR/issue-14091-2.rs:15:13 | LL | assert!(x, x); | ^ expected `bool`, found `BytePos` ``` `assert!(val)` now desugars to: ```rust match val { true => {}, _ => $crate::panic::panic_2021!(), } ``` Fix #122159. We make some minor changes to some diagnostics to avoid span overlap on type mismatch or inverted "expected"/"found" on type errors. We remove some unnecessary parens from core, alloc and miri. address review comments
2025-08-12Rollup merge of #145238 - estebank:attr-overhaul, r=jdonszelmannStuart Cook-3/+5
Tweak invalid builtin attribute output - Add link to reference/docs when possible - More accurate suggestions by supporting multiple alternative suggestions ``` error: malformed `crate_type` attribute input --> $DIR/crate-type-macro-call.rs:1:1 | LL | #![crate_type = foo!()] | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html> help: the following are the possible correct uses | LL - #![crate_type = foo!()] LL + #![crate_type = "bin"] | LL - #![crate_type = foo!()] LL + #![crate_type = "cdylib"] | LL - #![crate_type = foo!()] LL + #![crate_type = "dylib"] | LL - #![crate_type = foo!()] LL + #![crate_type = "lib"] | = and 4 other candidates ```
2025-08-11Extract ast TraitImplHeaderCameron Steffen-23/+31
2025-08-11Allow attr entries to declare list of alternatives for `List` and ↵Esteban Küber-3/+5
`NamedValueStr` Modify `AttributeTemplate` to support list of alternatives for list and name value attribute styles. Suggestions now provide more correct suggested code: ``` error[E0805]: malformed `used` attribute input --> $DIR/used_with_multi_args.rs:3:1 | LL | #[used(compiler, linker)] | ^^^^^^------------------^ | | | expected a single argument here | help: try changing it to one of the following valid forms of the attribute | LL - #[used(compiler, linker)] LL + #[used(compiler)] | LL - #[used(compiler, linker)] LL + #[used(linker)] | LL - #[used(compiler, linker)] LL + #[used] | ``` instead of the prior "masking" of the lack of this feature by suggesting pipe-separated lists: ``` error[E0805]: malformed `used` attribute input --> $DIR/used_with_multi_args.rs:3:1 | LL | #[used(compiler, linker)] | ^^^^^^------------------^ | | | expected a single argument here | help: try changing it to one of the following valid forms of the attribute | LL - #[used(compiler, linker)] LL + #[used(compiler|linker)] | LL - #[used(compiler, linker)] LL + #[used] | ```
2025-08-09remove `P`Deadbeef-174/+168
2025-08-06Port `#[should_panic]` to the new attribute parsing infrastructureJonathan Brouwer-34/+17
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-31remove rustc_attr_data_structuresJana Dönszelmann-3/+2
2025-07-28expand: Micro-optimize prelude injectionVadim Petrochenkov-3/+1
Use `splice` to avoid shifting the other items twice. Put `extern crate std;` first so it's already resolved when we resolve `::std::prelude::rust_20XX`.
2025-07-26Use the new attributes throughout the codebaseJonathan Brouwer-7/+21
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-18Rollup merge of #143925 - oli-obk:slice-const-partialeq, r=fee1-deadMatthias Krüger-3/+57
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