Commit graph

1783 commits

Author SHA1 Message Date
Stuart Cook
f7699054f7
Rollup merge of #152728 - Ozzy1423:default-lib, r=JonathanBrouwer
Port #![default_lib_allocator] to the new attribute parser

Tracking issue: https://github.com/rust-lang/rust/issues/131229

r? @JonathanBrouwer
2026-02-17 13:02:25 +11:00
Oscar Bray
8081e86c94 Port #![default_lib_allocator] to the new attribute parser 2026-02-16 19:42:12 +00:00
bors
3c9faa0d03 Auto merge of #148190 - RalfJung:box_new, r=RalfJung
replace box_new with lower-level intrinsics

The `box_new` intrinsic is super special: during THIR construction it turns into an `ExprKind::Box` (formerly known as the `box` keyword), which then during MIR building turns into a special instruction sequence that invokes the exchange_malloc lang item (which has a name from a different time) and a special MIR statement to represent a shallowly-initialized `Box` (which raises [interesting opsem questions](https://github.com/rust-lang/rust/issues/97270)).

This PR is the n-th attempt to get rid of `box_new`. That's non-trivial because it usually causes a perf regression: replacing `box_new` by naive unsafe code will incur extra copies in debug builds, making the resulting binaries a lot slower, and will generate a lot more MIR, making compilation measurably slower. Furthermore, `vec!` is a macro, so the exact code it expands to is highly relevant for borrow checking, type inference, and temporary scopes.

To avoid those problems, this PR does its best to make the MIR almost exactly the same as what it was before. `box_new` is used in two places, `Box::new` and `vec!`:
- For `Box::new` that is fairly easy: the `move_by_value` intrinsic is basically all we need. However, to avoid the extra copy that would usually be generated for the argument of a function call, we need to special-case this intrinsic during MIR building. That's what the first commit does.
- `vec!` is a lot more tricky. As a macro, its details leak to stable code, so almost every variant I tried broke either type inference or the lifetimes of temporaries in some ui test or ended up accepting unsound code due to the borrow checker not enforcing all the constraints I hoped it would enforce. I ended up with a variant that involves a new intrinsic, `fn write_box_via_move<T>(b: Box<MaybeUninit<T>>, x: T) -> Box<MaybeUninit<T>>`, that writes a value into a `Box<MaybeUninit<T>>` and returns that box again. In exchange we can get rid of somewhat similar code in the lowering for `ExprKind::Box`, and the `exchange_malloc` lang item. (We can also get rid of `Rvalue::ShallowInitBox`; I didn't include that in this PR -- I think @cjgillot has a commit for this somewhere [around here](https://github.com/rust-lang/rust/pull/147862/commits).)

See [here](https://github.com/rust-lang/rust/pull/148190#issuecomment-3457454814) for the latest perf numbers. Most of the regressions are in deep-vector which consists entirely of an invocation of `vec!`, so any change to that macro affects this benchmark disproportionally.

This is my first time even looking at MIR building code, so I am very low confidence in that part of the patch, in particular when it comes to scopes and drops and things like that.

I also had do nerf some clippy tests because clippy gets confused by the new expansion of `vec!` so it makes fewer suggestions when `vec!` is involved.

### `vec!` FAQ

- Why does `write_box_via_move` return the `Box` again? Because we need to expand `vec!` to a bunch of method invocations without any blocks or let-statements, or else the temporary scopes (and type inference) don't work out.
- Why is `box_assume_init_into_vec_unsafe` (unsoundly!) a safe function? Because we can't use an unsafe block in `vec!` as that would necessarily also include the `$x` (due to it all being one big method invocation) and therefore interpret the user's code as being inside `unsafe`, which would be bad (and 10 years later, we still don't have safe blocks for macros like this).
- Why does `write_box_via_move` use `Box` as input/output type, and not, say, raw pointers? Because that is the only way to get the correct behavior when `$x` panics or has control effects: we need the `Box` to be dropped in that case. (As a nice side-effect this also makes the intrinsic safe, which is imported as explained in the previous bullet.)
- Can't we make it safe by having `write_box_via_move` return `Box<T>`? Yes we could, but there's no easy way for the intrinsic to convert its `Box<MaybeUninit<T>>` to a `Box<T>`. Transmuting would be unsound as the borrow checker would no longer properly enforce that lifetimes involved in a `vec!` invocation behave correctly.
- Is this macro truly cursed? Yes, yes it is.
2026-02-16 18:46:10 +00:00
Ralf Jung
5e65109f21 add write_box_via_move intrinsic and use it for vec!
This allows us to get rid of box_new entirely
2026-02-16 17:27:40 +01:00
Jana Dönszelmann
12e6628977
Port rustc_nonnull_optimization_guaranteed to the new attribute parser 2026-02-16 09:46:04 +01:00
Jana Dönszelmann
47ca78040a
Port rustc_do_not_const_check to the new attribute parser 2026-02-16 09:38:31 +01:00
Jonathan Brouwer
923fb76303
Rollup merge of #152570 - Ozzy1423:attr-parse, r=JonathanBrouwer
Port #[rustc_test_marker] to the attribute parser

Tracking issue: https://github.com/rust-lang/rust/issues/131229

Targets:
Const is for normal tests (const test::TestDescAndFn is inserted before the test fn)
Const/Static/Fn is for custom_test_framework's #[test_case] e.g. tests/ui/custom_test_frameworks/full.rs

r? @JonathanBrouwer

Again I left the use-sites as is since they are early uses.
2026-02-14 18:55:37 +01:00
Jonathan Brouwer
cf0cb74612
Rollup merge of #152577 - Ozzy1423:macro-attr, r=JonathanBrouwer
Port #[rustc_proc_macro_decls] to the new attribute parser.

Tracking issue: https://github.com/rust-lang/rust/issues/131229

r? @JonathanBrouwer
2026-02-14 18:55:36 +01:00
Oscar Bray
6ed7615608 Port #[rustc_test_marker] to the attribute parser 2026-02-14 13:14:57 +00:00
Jacob Pratt
22f973db34
Rollup merge of #152568 - JonathanBrouwer:port_lang, r=jdonszelmann
Port `#[lang]` and `#[panic_handler]` to the new attribute parsers

For https://github.com/rust-lang/rust/issues/131229#issuecomment-2971351163

r? @jdonszelmann
2026-02-13 22:26:35 -05:00
Jacob Pratt
000d1f18bc
Rollup merge of #152076 - eggyal:undeclared-object-lifetime, r=fmease
Feed `ErrorGuaranteed` from late lifetime resolution errors through to bound variable resolution

If late lifetime resolution fails for whatever reason, forward to RBV the guarantee that an error was emitted - thereby eliminating the need for a "hack" to suppress subsequent/superfluous error diagnostics.

Fixes rust-lang/rust#152014
r? fmease
2026-02-13 22:26:32 -05:00
Alan Egerton
c43a33eec7
Feed ErrorGuaranteed from late lifetime resolution to RBV
If late lifetime resolution fails for whatever reason, forward to RBV
the guarantee that an error was emitted - thereby eliminating the need
for a "hack" to suppress subsequent/superfluous error diagnostics.
2026-02-13 16:24:39 +00:00
Jonathan Brouwer
c61c2603cf Port #[lang] to the new attribute parsers 2026-02-13 16:04:19 +00:00
Oscar Bray
ab13120882 Port #[rustc_proc_macro_decls] to the new attribute parser. 2026-02-13 13:24:37 +00:00
Jonathan Brouwer
a211e2fbba
Rollup merge of #152555 - JonathanBrouwer:port_diagnostic_item, r=jdonszelmann
Port `#[rustc_diagnostic_item]` to the new attribute parsers

r? @jdonszelmann
2026-02-13 13:34:59 +01:00
Jonathan Brouwer
cbc661022e Port #[rustc_diagnostic_item] to the new attribute parsers 2026-02-13 09:46:47 +00:00
Oscar Bray
8526aa5361 Port #[prelude_import] to the attribute parser 2026-02-12 17:43:04 +00:00
Oscar Bray
d1f11fd734 Port #![test_runner] to the attribute parser 2026-02-11 11:33:49 +00:00
Jana Dönszelmann
eab26e329b
Port rustc_no_mir_inline to the new attribute parser 2026-02-10 10:25:19 +01:00
Jana Dönszelmann
f4c135f91b
Port rustc_trivial_field_reads to the new attribute parser 2026-02-10 10:19:08 +01:00
Jana Dönszelmann
954f483557
Port rustc_never_type_options to the new attribute parser 2026-02-10 10:17:24 +01:00
Jana Dönszelmann
a17eb934db
Port rustc_capture_analysis to the new attribute parser 2026-02-10 10:10:38 +01:00
Jana Dönszelmann
9d10b2ff37
Port rustc_conversion_suggestion to the new attribute parser 2026-02-10 10:10:38 +01:00
Jana Dönszelmann
9cc2924959
Port rustc_deprecated_safe_2024 to the new attribute parser 2026-02-10 10:10:38 +01:00
Jana Dönszelmann
00fef81964
Port rustc_expected_cgu_reuse to the new attribute parser 2026-02-10 10:10:38 +01:00
bors
381e9ef09e Auto merge of #152324 - Keith-Cancel:mgca4, r=BoxyUwU
Update mgca to use `type const` syntax instead of the `#[type_const]` attribute. 

This PR changes the `#[type_const]` attribute to the `type const` syntax for  https://github.com/rust-lang/rust/issues/132980.

This will fixes https://github.com/rust-lang/rust/issues/151273 and similar issues, since we need to check `type const` of items before expansion. The move to add a syntax was mentioned here: https://github.com/rust-lang/rust/pull/151289#issuecomment-3765241397

The first part of this PR adds support by allowing `type const <IDENT>: <TYPE> { = <EXPR> };` syntax in `rustc_parse/src/parser/item.rs`.

The next part since the AST item does not contain enough information to determine if we have a `type const` was rework `ConstItemRhs` into `ConstItemRhsKind` to store the information since we no longer have the attribute acting as a source of extra data/metadata. 

The hir node `ConstItemRhsKind` current shape mostly works, except in the case of `TraitItemKind` where it is an option. I initially went about giving `hir::ConstItemRhsKind` a similar form the AST, but it touches a lot more lines of code and files so because of that, the less invasive option was to add a simple boolean flag to `TraitItemKind`. 

The forth part of this PR includes adding a query I called `is_rhs_type_const` so that we can handle both local and foreign def_ids. 

The fifth aspect of the PR is adding a `mgca_type_const_syntax` feature gate that is checked before expansion. The standard mgca feature gate is ran after expansion. This feature gate allows for conditional compilation (e.g #[cfg(..)]) of the `type const` syntax  in nightly without `min_generic_const_args` being enabled. 

The last bit is updating all the the tests that used the `#[type_const]` attribute to use the new syntax that failed because of the changes. This is the bulk of touched/edited files in the PR. 

r? @BoxyUwU 
@rustbot label +F-associated_const_equality +F-min_generic_const_args
2026-02-09 22:37:29 +00:00
Matthias Krüger
c1f716ae53
Rollup merge of #152131 - Ozzy1423:attrs6, r=JonathanBrouwer
Port rustc_no_implicit_bounds attribute to parser.

Tracking Issue: https://github.com/rust-lang/rust/issues/131229

r? @JonathanBrouwer
2026-02-09 18:39:42 +01:00
Keith-Cancel
73a991fb9d Allow provisional mgca syntax of type const <IDENT> = <EXPR> to be reconized.
Revert, but without type const.

Update symbol for feature err, then update suggestion output, and lastly update tests that change because of those.

Update these new tests with the correct syntax, and few existing tests with the new outputs the merge with main added.

Fix for tidyfmt and some errors when manually resolving a merge conflicts.

Update these tests to use update error messages and type const syntax.

Update comments and error message to use new syntax instead of old type_const attribute.

Remove the type_const attribute

update some more tests to use the new syntax.

Update these test cases.

update feature gate test

Change gate logic for `mgca_type_const_syntax` to work also if `min_generic_const_args` is enabled.

Create a new feature gate that checks for the feature before expansion.

Make rustfmt handle the `type const` syntax correctly.

Add a convience method to check if a RhsKind is type const.

Rename `Const` discriminant to `Body` for `ConstItemRhsKind`

Give the `TraitItemKind` flag an enum instead of a simple bool to better describe what the flag is for.

Update formatting for these match statements.

Update clippy test to use type const syntax.

Update test to use type const syntax.

update rustfmt to match ast items.

Update clippy to match ast and hir items.

Few more test cases that used old attribute, instead of 'type const'

Update to match the output from the feature gate checks.

tidyfmt adjustments.

Update the is_type_const, so I can constrain record!(..) in encoder.rs

Update conditional compilation test.

Move the feature gate to after expansion to allow for cfg(...) to work.

Update some more tests to use the new syntax.

Update type const tests in associated-const-bindings to use new syntax.

Don't check based off the attribute, but the item here.

Update some tests outside of the const_generics folder that were using #[type_const]

update the tests in associated consts that use #[type_const] to use type const

Update these mgca tests with the type const syntax.

Add a flag to TraitItemKind for detecting type const for now. Maybe later change ItemConstRhs to have optional consts but that touches a lot more lines of code.

Don't need into for these now that it's a query.

Add is_type_const query to handle foreign def ids.

update this test to use type const syntax.

Fix logic here, we only want to lower if there is expression in this case.

Update built-in macros to use ConstItemRhsKind

Update more instance of the old ConstItemRhs.

Rename ConstItemKind to ConstItemRhsKind, I noticed there is a typed called ConstantItemKind, so add the Rhs to the name to avoid confusion.

Update lower to use ConstItemKind

Add an other helper method to check if the rhs kinda has an expr.

Update item parse to use ConstItemKind enum.

Felt the field name could a be little clear when editing a few other things.

Change the ConstItem struct see know if we have a type const or regular const.

Make sure this syntax is properly feature gated.
2026-02-09 07:59:24 -08:00
Oscar Bray
2b22150c18 Port rustc_no_implicit_bounds attribute to parser. 2026-02-09 13:44:10 +00:00
Jana Dönszelmann
6babe687a5
Port rustc_reservation_impl to the new attribute parser 2026-02-09 10:55:22 +01:00
Stuart Cook
7cb4501916
Rollup merge of #152291 - jdonszelmann:port-rustc-insignificant-dtor, r=jonathanbrouwer
Port `rustc_insignificant_dtor`

r? @JonathanBrouwer

Second commit removes it from an impl in std. I looked, and I really think it had no effect in the past. We only look for this attr on ADTs...
2026-02-09 14:32:01 +11:00
Stuart Cook
12f0ef7480
Rollup merge of #152171 - jdonszelmann:port-rustc-strict-coherence, r=jonathanbrouwer
Port `rustc_strict_coherence` to the new attribute parser

r? @JonathanBrouwer
2026-02-09 14:32:00 +11:00
Jana Dönszelmann
2dda303229
Port rustc_strict_coherence to the new attribute parser 2026-02-08 22:28:58 +01:00
Jana Dönszelmann
f1b4c2a0e6
Port rustc_insignificant_dtor to the new attribute parser 2026-02-08 22:22:58 +01:00
Oscar Bray
6361d5f279 Parse #[rustc_outlives] 2026-02-08 11:41:36 +00:00
Oscar Bray
7668496274 Parse #[rustc_evaluate_where_clauses] 2026-02-08 11:41:10 +00:00
Oscar Bray
842bed6f93 Parse #[rustc_delayed_bug_from_inside_query] 2026-02-08 11:40:42 +00:00
Jonathan Brouwer
4230c3ab25
Rollup merge of #152300 - jdonszelmann:port-rustc-regions, r=JonathanBrouwer
Port `rustc_regions` to the new attribute parser

r? @JonathanBrouwer
2026-02-07 19:34:51 +01:00
Jana Dönszelmann
cf1a784f3f
Port rustc_regions to the new attribute parser 2026-02-07 17:24:40 +01:00
Jana Dönszelmann
c42a581d2f
Port rustc_intrinsic_const_stable_indirect to the new attribute parser 2026-02-07 14:12:56 +01:00
Jana Dönszelmann
9249e9f78a
Port rustc_intrinsic to the new attribute parser 2026-02-07 14:12:56 +01:00
Edvin Bryntesson
10f0c2d579
Port #[rustc_symbol_name] and #[rustc_def_path] to attr parser 2026-02-07 01:43:00 +01:00
Jonathan Brouwer
30bbeae0a5
Rollup merge of #152139 - khyperia:mgca-negative-literals, r=BoxyUwU
mGCA: Support directly represented negated literals

fixes rust-lang/rust#152123

PatExprKind already awkwardly tacks on a `negated: bool` for the same purpose:

8bccf1224d/compiler/rustc_hir/src/hir.rs (L1954-L1959)

perhaps one day we should indeed do that FIXME...

r? @BoxyUwU
2026-02-06 18:04:40 +01:00
khyperia
54a9be469a mGCA: Support directly represented negated literals 2026-02-06 14:04:55 +01:00
bors
035b01b794 Auto merge of #152213 - JonathanBrouwer:rollup-trjCgZZ, r=JonathanBrouwer
Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#152191 (Convert to inline diagnostics in `rustc_hir_analysis`)
 - rust-lang/rust#149329 (Mark match arms in try and for as being from desugarings.)
 - rust-lang/rust#151474 (Minor structural improvements)
 - rust-lang/rust#152107 (Convert to inline diagnostics in `rustc_borrowck`)
 - rust-lang/rust#152117 (Convert to inline diagnostics in `rustc_trait_selection`)
 - rust-lang/rust#152136 (Consolidate type const checks on `tcx.is_type_const`)
 - rust-lang/rust#152140 (Hard code the error code registry for custom drivers)
 - rust-lang/rust#152155 (Fix typos in riscv64a23-unknown-linux-gnu.md)
 - rust-lang/rust#152170 (Port `rustc_effective_visibility` to the new attribute parser)
 - rust-lang/rust#152182 (update compiler stable backport zulip msg)
 - rust-lang/rust#152184 (Port rustc_abi to the attribute parser)
 - rust-lang/rust#152195 (update openmp/offload builds to LLVM 22, Part 1)
 - rust-lang/rust#152202 (chore: clearify tidy's error message)

Failed merges:

 - rust-lang/rust#151744 (fix refining_impl_trait suggestion with return_type_notation)
 - rust-lang/rust#152212 (Port some attributes to the attr parser)
2026-02-06 09:12:28 +00:00
Jonathan Brouwer
0cc62c81e5
Rollup merge of #152184 - Ozzy1423:attrs3, r=jdonszelmann
Port rustc_abi to the attribute parser

Tracking issue: https://github.com/rust-lang/rust/issues/131229

This attribute either dumps the abi info for functions (debug arg)
or if you put it on a pair of fn ptr's it checks they match (assert_eq arg)

r? @JonathanBrouwer
2026-02-06 10:06:47 +01:00
Jonathan Brouwer
19f4c05129
Rollup merge of #152170 - jdonszelmann:port-rustc-effective-visibility, r=JonathanBrouwer
Port `rustc_effective_visibility` to the new attribute parser

r? @JonathanBrouwer
2026-02-06 10:06:46 +01:00
bors
cf16cd9b75 Auto merge of #152086 - nnethercote:stable-hashing-cleanups, r=cjgillot
Stable hashing cleanups

I took a close look at `rustc_query_system::ich` and found a bunch of things to improve.

r? @cjgillot
2026-02-06 06:02:23 +00:00
许杰友 Jieyou Xu (Joe)
7b821d1752
Rollup merge of #151278 - estebank:issue-108894, r=davidtwco
Provide more context on trait bounds being unmet due to imperfect derive

When encountering a value that has a borrow checker error where the type was previously moved, when suggesting cloning verify that it is not already being derived. If it is, explain why the `derive(Clone)` doesn't apply:

```
note: if `TypedAddress<T>` implemented `Clone`, you could clone the value
  --> $DIR/derive-clone-implicit-bound.rs:6:1
   |
LL | #[derive(Clone, Copy)]
   |          ----- derived `Clone` adds implicit bounds on type parameters
LL | pub struct TypedAddress<T>{
   | ^^^^^^^^^^^^^^^^^^^^^^^^-^
   | |                       |
   | |                       introduces an implicit `T: Clone` bound
   | consider manually implementing `Clone` for this type
...
LL |         let old = self.return_value(offset);
   |                                     ------ you could clone this value
```

When encountering a bound coming from a derive macro, suggest manual impl of the trait.

Use the span for the specific param when adding bounds in builtin derive macros, so the diagnostic will point at them as well as the derive macro itself.

```
note: required for `Id<SomeNode>` to implement `PartialEq`
  --> $DIR/derive-implicit-bound.rs:5:10
   |
LL | #[derive(PartialEq, Eq)]
   |          ^^^^^^^^^
LL | pub struct Id<T>(PhantomData<T>);
   |               - unsatisfied trait bound introduced in this `derive` macro
   = help: consider manually implementing `PartialEq` to avoid undesired bounds
```

Mention that the trait could be manually implemented in E0599.

Fix rust-lang/rust#108894. Address rust-lang/rust#143714. Address #rust-lang/rust#146515 (but ideally would also suggest constraining the fn bound correctly as well).
2026-02-06 10:25:43 +08:00
Nicholas Nethercote
7298e17366 Remove rustc_hir::HashStableContext::hash_attr_id.
It has a single impl, which does nothing, as you'd expect when hashing a
type called `HashIgnoredAttrId`!

So this commit just removes it, and `HashIgnoredAttrId::hash_stable`
ends up doing nothing (with a comment) instead of calling the trait
method to do nothing.
2026-02-06 09:18:18 +11:00