524 Commits

Author SHA1 Message Date
Nicholas Nethercote 15c6e6e092 Add a handle_cycle_error query modifier.
This modifier indicates that a query has a custom handler for cycles.
That custom handler must be found at
`rustc_query_impl::handle_cycle_error::$name`.

This eliminates the need for `specialize_query_vtables`, which is the
current hack to install custom handlers. It's more lines of code in
total, but indicating special treatment of a query via a modifier in
`queries.rs` is more consistent with how other aspects of queries are
handled.
2026-04-03 13:44:12 +11:00
Nicholas Nethercote d913766757 Remove the _description_fns module.
`rustc_queries` generates a macro and two modules. One of the modules
looks like this:
```
mod _description_fns {
    ...

    #[allow(unused_variables)]
    pub fn hir_module_items<'tcx>(tcx: TyCtxt<'tcx>, key: LocalModDefId) -> String {
	format!("getting HIR module items in `{}`", tcx.def_path_str(key))
    }

    ...
}
```
Members of this module are then used in `TaggedQueryKey::description`.

This commit removes the `_description_fns` module entirely. For each
query we now instead generate a description closure that is used
instead. This closure is passed in the modifiers list.

This change simplifies `rustc_queries` quite a bit. It requires adding
another query modifier, but query modifiers are how other query-specific
details are already passed to the declarative macros, so it's more
consistent.
2026-04-03 13:44:10 +11:00
Nicholas Nethercote aebce4c73f Process query modifiers in alphabetical order everywhere. 2026-04-03 13:10:55 +11:00
Nicholas Nethercote b651ab0d6c Add a useful comment.
I previously tried to remove this field because it seemed useless.
2026-04-03 13:10:55 +11:00
Nicholas Nethercote 1a9a284ad2 Simplify HashStableContext.
`derive(HashStable_Generic)` generates impls like this:
```
impl<__CTX> HashStable<__CTX> for ExpnKind
where
    __CTX: crate::HashStableContext
{
    fn hash_stable(&self, hcx : &mut __CTX, __hasher: &mut StableHasher) {
        ...
    }
}
```
This is used for crates that are upstream of `rustc_middle`.

The `crate::HashStableContext` bound means every crate that uses
`derive(HashStable_Generic)` must provide (or import) a trait
`HashStableContext` which `rustc_middle` then impls. In `rustc_span`
this trait is sensible, with three methods. In other crates, this trait
is empty, and there is the following trait hierarchy:
```
rustc_session::HashStableContext
  |              |
  |   rustc_hir::HashStableContext
  |         /                   \
rustc_ast::HashStableContext   rustc_abi::HashStableContext
  |
rustc_span::HashStableContext
```
All very strange and unnecessary. This commit changes
`derive(HashStable_Generic)` to use `rustc_span::HashStableContext`
instead of `crate::HashStableContext`. This eliminates the need for all
the empty `HashStableContext` traits and impls. Much better.
2026-04-01 17:52:43 +11:00
Zalathar a7d2a68378 Simplify the cache_on_disk_if modifier to just cache_on_disk
Queries with both `cache_on_disk` and `separate_provide_extern` will only
disk-cache values for local keys.

Other queries with `cache_on_disk` will disk-cache all values unconditionally.
2026-03-31 17:16:10 +11:00
Zalathar 3a62e89822 Remove the anon query modifier
We still have some anon-task machinery for `DepKind::TraitSelect` tasks, but
there are no longer any queries that use the `anon` modifier.
2026-03-21 14:22:10 +11:00
Zalathar dbdbf09586 Use a new no_force query modifier for check_representability
These queries appear to have been using `anon` for its side-effect of making
them ineligible for forcing.

According to their comments and also `tests/incremental/issue-61323.rs`, these
queries want to avoid forcing so that if a cycle does occur, the whole cycle
will be on the query stack for the cycle handler to find.
2026-03-21 14:22:10 +11:00
Zalathar 193309e1c3 Sort query modifier names in doc_link! 2026-03-21 14:11:24 +11:00
Zalathar e8ebfcaa2e Declare rustc_with_all_queries! as macros-2.0
Unlike `macro_rules!`, macros-2.0 macros have sensible item-like namespacing
and visibility by default, which avoids the need for `#[macro_export]` and
makes it easier to import the macro.

The tradeoff is having to use `#[rustc_macro_transparency = "semiopaque"]` to
still get macro-rules hygiene, because macros-2.0 hygiene is too strict here.
2026-03-15 13:23:19 +11:00
Zalathar 1038ed1bbc Use less #[macro_use] in the query system 2026-03-15 12:56:45 +11:00
Nicholas Nethercote c6c150b0e0 Remove CycleErrorHandling.
Currently if a cycle error occurs the error is created, then handled
according to `CycleErrorHandling` (which comes from the
`cycle_delay_bug` query modifer, or lack thereof), and then
`value_from_cycle_error` is called.

This commit changes things so the error is created and then just passed
to `value_from_cycle_error`. This gives `value_from_cycle_error` full
control over how it's handled, eliminating the need for
`CycleErrorHandling`. This makes things simpler overall.
2026-03-13 22:00:10 +11:00
Nicholas Nethercote 3399ed3c9a Simplify type_of_opaque.
There is a bunch of complexity supporting the "cannot check whether the
hidden type of opaque type satisfies auto traits" error that shows up in
`tests/ui/impl-trait/auto-trait-leak.rs`. This is an obscure error that
shows up in a single test. If we are willing to downgrade that error
message to a cycle error, we can do the following.

- Simplify the `type_of_opaque` return value.
- Remove the `cycle_stash` query modifier.
- Remove the `CyclePlaceholder` type.
- Remove the `SelectionError::OpaqueTypeAutoTraitLeakageUnknown`
  variant.
- Remove a `FromCycleError` impl.
- Remove `report_opaque_type_auto_trait_leakage`.
- Remove the `StashKey::Cycle` variant.
- Remove the `CycleErrorHandling::Stash` variant.

That's a lot! I think this is a worthwhile trade-off.
2026-03-11 21:54:42 +11:00
Nicholas Nethercote face186874 Use &C::Key less in queries.
Currently we use a mix of `C::Key` and `&C::Key` parameters. The former
is more common and a bit nicer, so convert some of the latter. This
results in less converting between the two types, and fewer sigils.
2026-03-08 22:54:12 +11:00
bors c7b206bba4 Auto merge of #153383 - nnethercote:overhaul-ensure_ok, r=Zalathar
Overhaul `ensure_ok`

The interaction of `ensure_ok` and the `return_result_from_ensure_ok` query modifier is weird and hacky. This PR cleans it up. Details in the individual commits.

r? @Zalathar
2026-03-08 07:03:35 +00:00
Nicholas Nethercote d4503b017e Overhaul ensure_ok.
`ensure_ok` provides a special, more efficient way of calling a query
when its return value isn't needed. But there is a complication: if the
query is marked with the `return_result_from_ensure_ok` modifier, then
it will return `Result<(), ErrorGuaranteed`. This is clunky and feels
tacked on. It's annoying to have to add a modifier to a query to declare
information present in its return type, and it's confusing that queries
called via `ensure_ok` have different return types depending on the
modifier.

This commit:

- Eliminates the `return_result_from_ensure_ok` modifier. The proc macro
  now looks at the return type and detects if it matches `Result<_,
  ErrorGuarantee>`. If so, it adds the modifier
  `returns_error_guaranteed`. (Aside: We need better terminology to
  distinguish modifiers written by the user in a `query` declaration
  (e.g. `cycle_delayed_bug`) from modifiers added by the proc macro
  (e.g. `cycle_error_handling`.))

- Introduces `ensure_result`, which replaces the use of `ensure_ok` for
  queries that return `Result<_, ErrorGuarantee>`. As a result,
  `ensure_ok` can now only be used for the "ignore the return value"
  case.
2026-03-08 09:39:39 +11:00
Josh Stone 32bae1353e Update cfg(bootstrap) 2026-03-07 10:42:02 -08:00
Jonathan Brouwer e58ddb5ae5 Fix variable_references logic to catch all variable references 2026-03-06 18:52:11 +01:00
Jonathan Brouwer 46cedc33b8 Use eager formatting in #[derive(Subdiagnostic)] 2026-03-06 18:32:54 +01:00
Jonathan Brouwer 53ef4d297e Rollup merge of #153414 - JonathanBrouwer:translate_cleanup, r=Kivooeo
Rename translation -> formatting

Because there is no translation happening anymore

r? @Kivooeo
2026-03-04 19:30:42 +01:00
Jonathan Brouwer 1500680ba5 Rollup merge of #153401 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer
Migrationg of `LintDiagnostic` - part 7

Part of https://github.com/rust-lang/rust/issues/153099.

This PR removes the `LintDiagnostic` trait and proc-macro. \o/

r? @JonathanBrouwer
2026-03-04 19:30:40 +01:00
Jonathan Brouwer d8092147fe Rename translation -> formatting 2026-03-04 17:47:24 +01:00
Guillaume Gomez 828398e986 Remove LintDiagnostic derive proc-macro 2026-03-04 15:16:52 +01:00
John Kåre Alsaker 91c7627c0f Remove cycle_fatal query modifier
This removes the `cycle_fatal` query modifier as it has no effect on its current users.

The default `CycleErrorHandling::Error` mode does the same as `cycle_fatal` when the default impl of `FromCycleError` is used. The return types of queries using `cycle_fatal` however have no specialized `FromCycleError` impl.
2026-03-04 08:14:34 +01:00
Zalathar 083b5db476 Make rustc_with_all_queries! pass query modifiers as named values 2026-03-03 16:43:46 +11:00
Nicholas Nethercote 253c6965bc Make non-queries available to rustc_with_all_queries.
`rustc_with_all_queries` currently provides information about all
queries. Also, a caller can provide an ad hoc list of extra non-queries.
This is used by `define_queries` for non-query dep kinds: `Null`, `Red`,
etc. This is pretty hacky.

This commit changes `rustc_with_all_queries` so that the non-queries
information is available to all callers. (Some callers ignore the
non-query information.) This is done by adding `non_query` entries to
the primary list of queries in `rustc_queries!`.
2026-03-02 15:26:41 +11:00
bors ba1567989e Auto merge of #153217 - JonathanBrouwer:rollup-iXVG70B, r=JonathanBrouwer
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#153211 (`rust-analyzer` subtree update)
 - rust-lang/rust#149027 (Improve cross-crate trait impl param mismatch suggestions )
 - rust-lang/rust#152730 (add field representing types)
 - rust-lang/rust#153136 (Correctly handle `#[doc(alias = "...")]` attribute on inlined reexports)
 - rust-lang/rust#152165 (Normalize capture place `ty`s to prevent ICE)
 - rust-lang/rust#152615 (refactor 'valid for read/write' definition: exclude null)
 - rust-lang/rust#153109 (Fix LegacyKeyValueFormat report from docker build: aarch64-gnu-debug)
 - rust-lang/rust#153172 (Fix comment about placeholders)
 - rust-lang/rust#153187 (Fix ICE when macro-expanded extern crate shadows std)
 - rust-lang/rust#153190 (Don't allow subdiagnostic to use variables from their parent)
 - rust-lang/rust#153200 (Remove redundant clone)
 - rust-lang/rust#153216 (mark two polonius tests as known-bug)
2026-02-28 12:23:16 +00:00
bors 1d113d2f30 Auto merge of #152948 - GrigorenkoPV:sym-ascii, r=JonathanBrouwer
pre-intern single-letter `sym::[a-zA-Z]`

As suggested in https://github.com/rust-lang/rust/pull/152624#discussion_r2822059367.

Needs a perf run I guess.
2026-02-28 08:38:11 +00:00
Jonathan Brouwer d52424c424 Check usages of variables in subdiagnostics 2026-02-27 14:41:26 +00:00
Jacob Pratt f8f444757d Rollup merge of #153029 - nnethercote:disallowed-pass-by-ref, r=Urgau
Rename `rustc::pass_by_value` lint as `rustc::disallowed_pass_by_ref`.

The name `pass_by_value` is completely wrong. The lint actually checks for the use of pass by reference for types marked with `rustc_pass_by_value`.

The hardest part of this was choosing the new name. The `disallowed_` part of the name closely matches the following clippy lints:
- `disallowed_macros`
- `disallowed_methods`
- `disallowed_names`
- `disallowed_script_idents`
- `disallowed_types`

The `pass_by_value` part of the name aligns with the following clippy lints:
- `needless_pass_by_value`
- `needless_pass_by_ref_mut`
- `trivially_copy_pass_by_ref`
- `large_types_passed_by_value` (less so)

r? @Urgau
2026-02-25 21:42:57 -05:00
Nicholas Nethercote 8eed8bd7bb Rename pass_by_value lint as disallowed_pass_by_ref.
The name `pass_by_value` is completely wrong. The lint actually checks
for the use of pass by reference for types marked with
`rustc_pass_by_value`.

The hardest part of this was choosing the new name. The `disallowed_`
part of the name closely matches the following clippy lints:
- `disallowed_macros`
- `disallowed_methods`
- `disallowed_names`
- `disallowed_script_idents`
- `disallowed_types`

The `pass_by_value` part of the name aligns with the following clippy
lints:
- `needless_pass_by_value`
- `needless_pass_by_ref_mut`
- `trivially_copy_pass_by_ref`
- `large_types_passed_by_value` (less so)
2026-02-25 15:10:14 +11:00
Nicholas Nethercote 8ac769f9d0 Remove rustc_feedable_queries and define_feedable macros.
`rustc_queries!` produces two macros: `rustc_with_all_queries` and
`rustc_feedable_queries`. The latter is similar to the former but only
includes feedable queries.

But feedable queries don't need a separate mechanism because we can
identify feedable queries within `define_callbacks!` by just looking for
the `feedable` modifier. (That's what we do with every modifier other
than `feedable`.)

This commit removes the special handling and treats feedable queries
like everything else.

Note that this commit exposes and fixes a latent doc bug. The doc
comment for query `explicit_predicates_of` links to
`Self::predicates_of`. `explicit_predicates_of` is a feedable query but
`predicates_of` is not, so for `TyCtxtFeed` this link is invalid. This
wasn't manifesting because `TyCtxtFeed` wasn't getting doc comments
attached. It now is, so I changed the link to `TyCtxt::predicates_of`.
2026-02-24 08:09:44 +11:00
Stuart Cook 8c96521c99 Rollup merge of #152987 - Zoxc:hashstable-derives, r=JonathanBrouwer
Use `HashStable` derive in more places

This applies `HashStable` derive in a couple more places. Also `stable_hasher` is declared for `HashStable_NoContext`.
2026-02-23 13:32:01 +11:00
John Kåre Alsaker 912c7d31d2 Use HashStable derive in more places 2026-02-22 21:01:27 +01:00
Nicholas Nethercote ecb778fc61 Remove explicit tcx bindings from query entries.
As currently written, these have big problems.
- `desc` and `cache_on_disk_if` modifiers use different syntaxes to
  introduce `tcx`.
- `desc` is mis-implemented such that the explicit binding isn't even
  necessary and the key name can be botched, as the previous two commits
  showed. (It's the `let (#tcx, #key) = (tcx, key);` line that messes
  things up.)

It's simpler and less error-prone to simply not require explicit `tcx`
bindings, and instead just make it implicitly available to these code
snippets.
2026-02-22 19:08:26 +11:00
Pavel Grigorenko abcdef0640 pre-intern single-letter sym::[a-zA-Z] 2026-02-22 01:00:22 +03:00
Jonathan Brouwer 412b0c3efc Rollup merge of #152846 - Zalathar:query-proc-macro, r=nnethercote
Clarify some variable names in the query proc-macro

These are some cleanups to the `rustc_macros::query`, extracted from https://github.com/rust-lang/rust/pull/152833.

r? nnethercote
2026-02-20 13:24:58 +01:00
Zalathar ede72796ba Clarify some variable names in the query proc-macro 2026-02-19 22:54:22 +11:00
Esteban Küber 37684bdfc5 Make all multipart suggestions verbose
The ShowAlways style of suggestions is usually easier to understand than the inline style.
2026-02-18 18:33:35 +00:00
Nicholas Nethercote e9288e7e90 Remove last remnants of rustc_query_system.
At this point module `ich` is the only thing left.
2026-02-16 22:56:47 +11:00
bjorn3 fa753a46c1 Remove code for ThinLTO from cg_gcc
It was just a dummy implementation to workarround the fact that thin
local lto is the default in rustc. By adding a thin_lto_supported thin
local lto can be automatically disabled for cg_gcc, removing the need
for this dummy implementation. This makes improvements to the LTO
handling on the cg_ssa side a lot easier.
2026-02-15 10:05:48 +00:00
Jonathan Brouwer 018a5efcf7 Rename inline_fluent! to msg! 2026-02-14 13:47:52 +01:00
Jonathan Brouwer f1b935d08f Rollup merge of #152356 - JonathanBrouwer:inline_diag4, r=jdonszelmann
Improve the `inline_fluent!` macro

For https://github.com/rust-lang/rust/issues/151366

This PR turns `inline_fluent!` into a proc macro, so we can run validation on the messages in this macro :)
I started a thread here because I don't like the name of the macro, but that's for a future PR: [#t-compiler > Bikeshed the new &#96;inline_fluent!&#96; macro](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Bikeshed.20the.20new.20.60inline_fluent!.60.20macro/with/572646242)
2026-02-13 13:35:01 +01:00
Jonathan Brouwer 65d982abd8 Rollup merge of #152469 - mu001999-contrib:cleanup/unused-features, r=nadrieril,jdonszelmann
Remove unused features

Detected by https://github.com/rust-lang/rust/pull/152164.

~~Only allow `unused_features` if there are complex platform-specific features enabled.~~
2026-02-13 13:34:58 +01:00
mu001999 a07f837491 Remove unused features in compiler 2026-02-13 09:25:39 +08:00
John Kåre Alsaker 8cc4b936a4 Change query proc macro to be more rust-analyzer friendly 2026-02-12 12:39:51 +01:00
bors 7b25457166 Auto merge of #151943 - Zalathar:cache-on-disk, r=TaKO8Ki
Clean up query macros for `cache_on_disk_if`

This PR aims to make the macros for dealing with `cache_on_disk_if` a bit easier to read and work with.

There should be no change to compiler behaviour.
2026-02-10 20:57:44 +00:00
Jonathan Brouwer faa15808cf Rollup merge of #152355 - JonathanBrouwer:update-macro-doc, r=nnethercote
Update documentation of rustc_macros

Update the docs to reflect the changes in https://github.com/rust-lang/rust/issues/151366
2026-02-10 13:00:49 +01:00
Jonathan Brouwer 2377d355ad Update documentation of rustc_macros 2026-02-10 10:17:59 +01:00
Jonathan Brouwer 41e0e0690f Move inline_fluent to a proc macro 2026-02-09 19:12:13 +01:00