Commit graph

9833 commits

Author SHA1 Message Date
Matthias Krüger
2194af9680
Rollup merge of #152419 - nnethercote:mv-more-query-system-code, r=Zalathar
Move more query system code

Towards the goal of eliminating `rustc_query_system`, this commit moves some code from `rustc_query_system` to `rustc_middle` and `rustc_query_impl`, and from `rustc_middle` to `rustc_query_impl`.

r? @Zalathar
2026-02-11 13:48:46 +01:00
Zalathar
0de45db240 Clarify names of QueryVTable functions for "executing" a query
This also changes the signature of `call_query_method` to not return a value,
because its only caller immediately discards the value anyway.
2026-02-11 16:50:10 +11:00
Jonathan Brouwer
083622cdd0
Rollup merge of #152396 - ShoyuVanilla:uplift-allow-normalize, r=lcnr
Uplift `Predicate::allow_normalization` to `rustc_type_ir`

Found this FIXME comment while fixing a bug in rust-analyzer 😄
cc https://github.com/rust-lang/rust-analyzer/pull/21611

r? types
2026-02-10 13:00:49 +01:00
Jonathan Brouwer
5541e5c057
Rollup merge of #152417 - Zalathar:arena-alloc, r=nnethercote
Move the needs-drop check for `arena_cache` queries out of macro code

This is slightly simpler than before, because now the macro only needs to call a single function, and can just unconditionally supply `tcx` and a typed arena.

There should be no actual change to compiler behaviour.
2026-02-10 13:00:47 +01:00
Jonathan Brouwer
2aaf3a19d5
Rollup merge of #152148 - Zalathar:tcx-interner, r=petrochenkov
Move `impl Interner for TyCtxt` to its own submodule

This impl is several hundred lines of mostly self-contained, mostly boilerplate code that can be extracted out of the dauntingly large `rustc_middle::ty::context` module.

- The trait and its impl were introduced by https://github.com/rust-lang/rust/pull/97287.

---

There should be no change to compiler behaviour.
2026-02-10 13:00:45 +01:00
Nicholas Nethercote
923de04f6a Move rustc_middle::query::values to rustc_query_impl.
Because all uses are now in `rustc_query_impl`. This was made possible
by the previous commit. Less code in `rustc_middle`, hooray.
2026-02-10 18:46:05 +11:00
Shoyu Vanilla
20f65fc537 Uplift Predicate::allow_normalization to rustc_type_ir 2026-02-10 12:26:12 +09:00
Zalathar
4dc82e99ef Move the needs-drop check for arena_cache queries out of macro code 2026-02-10 13:23:25 +11:00
Zalathar
b7bfb768d0 Indicate that bidirectional_lang_item_map! declares functions
Requiring `fn` in the macro syntax makes it a little more obvious that the
macro declares functions with those names, and makes them easier to grep for.
2026-02-10 12:03:40 +11:00
Zalathar
4234d2dd72 Move impl Interner for TyCtxt to its own submodule 2026-02-10 12:03:39 +11:00
Zalathar
91d47a5c0d Don't import TyCtxt from crate::ty::context 2026-02-10 11:58:44 +11: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
Jonathan Brouwer
6eb2a8fa9e
Reformat existing error messages 2026-02-09 19:12:22 +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
Zalathar
e04ae80c5a Rename JobOwner to ActiveJobGuard
This commit also adds and updates some relevant comments.
2026-02-10 00:20:45 +11:00
bors
c6936c309a Auto merge of #152371 - nnethercote:rm-QueryDispatcher, r=Zalathar
Remove `QueryDispatcher`

`QueryDispatcher` is a trait that existed purely because `rustc_query_system` had code that didn't have access to `TyCtxt`. That is no longer the case, so the trait can be removed.

r? @Zalathar
2026-02-09 09:34:09 +00:00
Nicholas Nethercote
f9958048e0 Move HashResult.
It's the only thing left in `rustc_query_system::query::dispatcher`.
2026-02-09 20:02:43 +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
Stuart Cook
7ae47be6aa
Rollup merge of #150823 - camelid:ogca, r=BoxyUwU
Implement MVP for opaque generic const arguments

This is meant to be the interim successor to generic const expressions.
Essentially, const item RHS's will be allowed to do arbitrary const
operations using generics. The limitation is that these const items will
be treated opaquely, like ADTs in nominal typing, such that uses of them
will only be equal if the same const item is referenced. In other words,
two const items with the exact same RHS will not be considered equal.

I also added some logic to check feature gates that depend on others
being enabled (like oGCA depending on mGCA).

### Coherence

During coherence, OGCA consts should be normalized ambiguously because
they are opaque but eventually resolved to a real value. We don't want
two OGCAs that have the same value to be treated as distinct for
coherence purposes. (Just like opaque types.)

This actually doesn't work yet because there are pre-existing
fundamental issues with equate relations involving consts that need to
be normalized. The problem is that we normalize only one layer of the
const item and don't actually process the resulting anon const. Normally
the created inference variable should be handled, which in this case
would cause us to hit the anon const, but that's not happening.
Specifically, `visit_const` on `Generalizer` should be updated to be
similar to `visit_ty`.

r? @BoxyUwU
2026-02-09 14:31:59 +11:00
Jana Dönszelmann
2dda303229
Port rustc_strict_coherence to the new attribute parser 2026-02-08 22:28:58 +01:00
Noah Lev
9a30ec8149 Implement MVP for opaque generic const arguments
This is meant to be the interim successor to generic const expressions.
Essentially, const item RHS's will be allowed to do arbitrary const
operations using generics. The limitation is that these const items will
be treated opaquely, like ADTs in nominal typing, such that uses of them
will only be equal if the same const item is referenced. In other words,
two const items with the exact same RHS will not be considered equal.

I also added some logic to check feature gates that depend on others
being enabled (like oGCA depending on mGCA).

= Coherence =

During coherence, OGCA consts should be normalized ambiguously because
they are opaque but eventually resolved to a real value. We don't want
two OGCAs that have the same value to be treated as distinct for
coherence purposes. (Just like opaque types.)

This actually doesn't work yet because there are pre-existing
fundamental issues with equate relations involving consts that need to
be normalized. The problem is that we normalize only one layer of the
const item and don't actually process the resulting anon const. Normally
the created inference variable should be handled, which in this case
would cause us to hit the anon const, but that's not happening.
Specifically, `visit_const` on `Generalizer` should be updated to be
similar to `visit_ty`.
2026-02-08 18:15:11 +00:00
bors
286fbe5d84 Auto merge of #152160 - nnethercote:start-cutting-down-rustc_query_system, r=Zalathar
Start cutting down `rustc_query_system`

The query system is implemented in `rustc_query_system`, `rustc_middle`, and `rustc_query_impl`. `rustc_query_system` is hamstrung by not having access to `TyCtxt`, and there seems to be consensus to eliminate it. It's contents can be moved into the other two crates. Moving as much stuff as possible to `rustc_query_impl` is preferred, because `rustc_middle` is already so big.

This PR starts this process. It moves one small function to `rustc_middle` and a good chunk of code to `rustc_query_impl`.

Once `rustc_query_system` is gone (or at least shrunk down a lot more) some of the traits like `DepContext`, `QueryContext`, and `QueryDispatcher` will be removable.

r? @Zalathar
2026-02-08 11:41:28 +00:00
bors
be4794c78b Auto merge of #152321 - Zalathar:rollup-ezxwhfJ, r=Zalathar
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#150443 (Support long diff conflict markers)
 - rust-lang/rust#151887 (Remove some unnecessary `try`-related type annotations)
 - rust-lang/rust#152037 (Suppress unused_mut lint if mutation fails due to borrowck error)
 - rust-lang/rust#152067 (Weaken `assert_dep_node_not_yet_allocated_in_current_session` for multiple threads)
 - rust-lang/rust#151227 (Document `-Zcache-proc-macros`)
2026-02-08 08:12:38 +00:00
Stuart Cook
68f4a99963
Rollup merge of #151887 - scottmcm:homogeneous-try-in-compiler, r=jackh726
Remove some unnecessary `try`-related type annotations

I left a few, like
```rust
let result: Result<_, ModError<'_>> = try {
```
where it felt like seeing it might still be useful for the reader.

Feel free to push back on any of these changes if you think they should be left alone.
2026-02-08 16:58:23 +11:00
bors
13c38730d9 Auto merge of #150485 - dianqk:gvn-ssa-borrow, r=cjgillot
GVN: Only propagate borrows from SSA locals

Fixes https://github.com/rust-lang/rust/issues/141313. This is a more principled fix than https://github.com/rust-lang/rust/pull/147886.

Using a reference that is not a borrowing of an SSA local at a new location may be UB.

The PR has two major changes.

The first one, when introducing a new dereference at a new location, is that the reference must point to an SSA local or be an immutable argument. `dereference_address` has handled SSA locals.

The second one, if we cannot guard to the reference point to an SSA local in `visit_assign`, we have to rewrite the value to opaque. This avoids unifying the following dereferences that also are references:

```rust
let b: &T = *a;
// ... `a` is allowed to be modified. `c` and `b` have different borrowing lifetime.
// Unifying them will extend the lifetime of `b`.
let c: &T = *a; 
```

See also https://github.com/rust-lang/rust/issues/130853.

This still allows unifying non-reference dereferences:

```rust
let a: &T = ...;
let b: T = *a;
// ... a is NOT allowed to be modified.
let c: T = *a; 
```

r? @cjgillot
2026-02-08 05:03:48 +00:00
Nicholas Nethercote
58e4a341b6 Move try_get_cached from rustc_query_system to rustc_middle.
That's the only place it's used, so it no longer needs to be `pub`.
2026-02-08 14:15:39 +11:00
Jonathan Brouwer
725eb60ded
Rollup merge of #152261 - fmease:has-own-self, r=BoxyUwU
Introduce helper `ty::Generics::has_own_self`

The pattern `generics.has_self && generics.parent.is_none()` only occurs 5 times in rustc+rustdoc at the time of writing but I keep getting reminded/annoyed that there doesn't exist a nice wrapper fn that abstracts it & immediately clarifies the intent. Most recently that happened when working on my open PR RUST-129543 in which I add yet another occurrence of it ([via](ae8c0a5a46/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs (L1771-L1773))).

For context, `generics.has_self` indicates that there is a `Self` type parameter (at position 0) in the "oldest" / "root" generic parameter list in the chain of generic parameter lists (rephrased: it's true if the chain *as a whole* has a `Self` type parameter). `has_own_self` on the other hand indicates that the `own_params` contain a `Self` type parameter which is sometimes needed for offsetting the own parameters or arguments.
2026-02-07 19:34:50 +01:00
bors
c7f5f3e0d5 Auto merge of #152294 - JonathanBrouwer:rollup-ygNTxe8, r=JonathanBrouwer
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#149960 (add `unreachable_cfg_select_predicates` lint)
 - rust-lang/rust#152168 (Port `rustc_intrinsic_const_stable_indirect` and `rustc_intrinsic` to the new attribute parser)
 - rust-lang/rust#152289 (Also duplicate `#[expect]` attribute in `#[derive]`-ed code)
2026-02-07 15:20:28 +00: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
Jonathan Brouwer
ae9d2d9395
Rollup merge of #152199 - nnethercote:rm-rustc_query_system-cache, r=Zalathar
Move `rustc_query_system::cache`.

It only defines two types, `Cache` and `WithDepNode`. Neither has anything much to do with queries -- they use `DepNodeIndex`, that's all.

This commit moves the module into `rustc_middle`, to where they are used. It also renames the extremely non-descriptive `Cache` as `WithDepNodeCache`.

r? @Zalathar
2026-02-07 13:06:36 +01:00
Nicholas Nethercote
b49ab57d6b Rename Cache as WithDepNodeCache.
Because `Cache` is unhelpfully vague.
2026-02-07 14:14:16 +11:00
Nicholas Nethercote
b29a9b6920 Move rustc_query_system::cache to rustc_middle::traits. 2026-02-07 14:06:46 +11:00
León Orell Valerian Liehr
5ea37f7add
Introduce helper ty::Generics::has_own_self 2026-02-06 23:45:57 +01:00
Jonathan Brouwer
a9b4c7cfc9
Rollup merge of #152000 - lapla-cogito:ice_151027, r=BoxyUwU
Fix ICE in normalizing inherent associated consts with `#[type_const]`

Fixes rust-lang/rust#151027
Fixes rust-lang/rust#138089
Fixes rust-lang/rust#138226
Fixes rust-lang/rust#150960

When an inherent associated const is marked with `#[type_const]`, its generics expect args in the format `[Self, own_params...]`, similar to inherent associated types. However, HIR typeck's `instantiate_value_path` was constructing args in the regular associated const format `[impl_params..., own_params...]`. This mismatch caused ICEs when the `args` were later used in contexts expecting the IAC format, such as user type annotations and `borrowck`'s type ascription.
2026-02-06 15:33:40 +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
ce706cd4ef
Rollup merge of #152136 - eggyal:consolidate-type-const-checks, r=BoxyUwU
Consolidate type const checks on `tcx.is_type_const`

A little bit of cleanup; explanation can be found in the reporting issue.

Fixes rust-lang/rust#152124
r? BoxyUwU
2026-02-06 10:06:44 +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
lapla
43947428ff
Extend check_args_compatible to handle IACs 2026-02-06 14:44:00 +09: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
e35fd451a0 Add a useful comment about the RawList stable hash cache.
I tried removing it to see what happened. Not a good idea!
2026-02-06 09:18:19 +11:00
bors
f889772d65 Auto merge of #152096 - bjorn3:mir_encoding_cleanups, r=oli-obk
Couple of cleanups and optimizations around MIR encoding
2026-02-05 15:30:48 +00:00
Jonathan Brouwer
4d535f5642
Rollup merge of #152119 - JonathanBrouwer:convert_middle, r=jdonszelmann
Convert to inline diagnostics in `rustc_middle`

For https://github.com/rust-lang/rust/issues/151366
r? @jdonszelmann
2026-02-05 12:17:01 +01:00
Jonathan Brouwer
ce3df42e35
Rollup merge of #152153 - Zalathar:descs, r=nnethercote
Incorporate query description functions into `QueryVTable`

Putting a `desc` function in each query vtable reduces the amount of parameter juggling required when creating query stack frames, because almost all of the necessary information can be found in the vtable.

There should be no change to compiler output.
2026-02-05 12:16:58 +01:00
Jonathan Brouwer
46753b1b43
Convert to inline diagnostics in rustc_middle 2026-02-05 12:02:02 +01:00
Zalathar
438220673f Incorporate query description functions into QueryVTable 2026-02-05 18:41:34 +11:00
Jonathan Brouwer
cf2ea13042
Rollup merge of #152023 - nnethercote:rm-Value, r=nnethercote
Some `rustc_query_system` cleanups

Small improvements I found while looking closely at `rustc_query_system`. Best reviewed one commit at a time.

r? @cjgillot
2026-02-05 08:32:46 +01:00
Jonathan Brouwer
c5381dd987
Rollup merge of #152033 - Zalathar:dep-node-key, r=nnethercote
Rename trait `DepNodeParams` to `DepNodeKey`

In query system plumbing, we usually refer to a query's explicit argument value as a “key”.

The first few commits do some preliminary cleanup that would conflict with the rename; the rename itself is in the final commit.

r? nnethercote (or compiler)
2026-02-05 08:32:44 +01:00
Nicholas Nethercote
7bcb7a281e Move rustc_middle::values module to rustc_middle::query::values.
It's a better place for it, because it relates to queries.
2026-02-05 09:29:43 +11:00
Nicholas Nethercote
a68bb0c371 Move rustc_query_system::values module into rustc_middle.
It's a tiny module with one trait and a default impl. It's not used in
`rustc_query_system`; all uses and non-default impls are in
`rustc_middle` and `rustc_query_impl`.

This commit moves it into `rustc_middle`, which makes things simpler
overall.
2026-02-05 08:15:16 +11:00