Commit Graph

10346 Commits

Author SHA1 Message Date
Nicholas Nethercote 809fcab63e Shift lift calls outward.
Several printing functions (e.g. `short_string`) take a liftable
parameter. This commit changes the call sites to do the lifting instead.
This simplifies the type signatures and puts the `lift` calls inside
`tls::with` calls which is where they usually appear, and the minor cost
of having more `lift` call sites.
2026-05-04 14:05:16 +10:00
Nicholas Nethercote 67ba480fdb Remove unused 'tcx lifetime from trait Print. 2026-05-04 14:04:55 +10:00
Jonathan Brouwer 081e7c4481 Rollup merge of #155433 - oli-obk:bye-bye-long-attribute, r=RalfJung,ShoyuVanilla
Rip out rustc_layout_scalar_valid_range_* attribute support

And either removes tests for it or replaces the uses with pattern types.

primarily fixes rust-lang/rust#135996

fixes rust-lang/rust#147761
fixes rust-lang/rust#133652
2026-05-03 16:33:22 +02:00
Oli Scherer 11d88ee42b Rip out rustc_layout_scalar_valid_range_* attribute support 2026-05-03 10:59:52 +02:00
Jacob Pratt c3afa21a40 Rollup merge of #156065 - mejrs:spanculler, r=JonathanBrouwer
Remove unused spans from AttributeKind

Recently I noticed some spans in diagnostic attributes were never used. I went through and checked the other variants too.
2026-05-03 00:25:33 -04:00
Jacob Pratt cc82c429f0 Rollup merge of #155666 - nnethercote:interning-cleanups, r=mejrs
Interning cleanups

Details in individual commits.

r? @JohnTitor
2026-05-03 00:25:32 -04:00
mejrs 4a13f36265 Remove more spans from AttributeKind 2026-05-02 17:41:30 +02:00
Ralf Jung e402c1edf0 miri: remove retag statements, make typed copies retag implicitly instead 2026-05-02 17:40:33 +02:00
Jonathan Brouwer 716bccea07 Rollup merge of #156028 - scottmcm:local-arg, r=wesleywiser
Add a `Local::arg(i)` helper constructor

While reading through stuff I was noticing just how many `+1` fixes there were in various places (and comments explaining those fixups), so this adds a new inherent helper on `Local` for making an argument to help make this clearer.

r? mir
2026-05-02 10:18:28 +02:00
Jonathan Brouwer 9149135815 Rollup merge of #156021 - nnethercote:clean-up-some-traits, r=jackh726
Clean up some traits

I was looking at various traits and found some unnecessary trait bounds, and some unnecessary traits. Details in individual commits.

r? @Nadrieril
2026-05-02 10:18:28 +02:00
Nicholas Nethercote e7d28d3e9b Rename the HashStable* trait/derives as StableHash*.
Specifically:
- `HashStable` -> `StableHash` (trait)
- `HashStable` -> `StableHash` (derive)
- `HashStable_NoContext` -> `StableHash_NoContext` (derive)

Note: there are some names in `compiler/rustc_macros/src/hash_stable.rs`
that are still to be renamed, e.g. `HashStableMode`.

Part of MCP 983.
2026-05-02 10:16:40 +02:00
Nicholas Nethercote 846267e725 Rename the HashStableContext trait as StableHashCtxt.
Part of MCP 983.
2026-05-02 10:16:39 +02:00
Nicholas Nethercote 851049cf58 Rename the hash_stable method as stable_hash.
Part of MCP 983.
2026-05-02 10:15:59 +02:00
Guillaume Gomez e95df7d6d5 Rollup merge of #155749 - ShoyuVanilla:leakcheck-vis, r=lcnr
`-Znext-solver` Ignore region constraints from the nested goals in leakcheck

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/251
Fixes https://github.com/rust-lang/rust/issues/140577
Fixes https://github.com/rust-lang/rust/issues/153596
2026-05-02 04:12:05 +02:00
bors 67bcaa9c4b Auto merge of #153968 - jyn514:jyn/linker-warn-by-default, r=mati865
linker-messages is warn-by-default again

cc rust-lang/rust#136096 

I ended up keeping it a lint and adding an option for lints to ignore `-Dwarnings` (there was already a lint that did that actually, it was just hard-coded in rustc_middle instead of in rustc_lint_defs like I'd expect). This allows people to actually see the warnings without them failing the build in CI.
2026-05-01 17:15:17 +00:00
Shoyu Vanilla e43a1b5b44 -Znext-solver Ignore region constraints from the nested goals in leakcheck 2026-05-02 00:11:43 +09:00
Jonathan Brouwer 7c4d304d4b Rollup merge of #156019 - nnethercote:rm-Feed, r=oli-obk
Feed cleanups

Two minor improvements. Details in the individual commits.

r? @oli-obk
2026-05-01 13:10:37 +02:00
Jonathan Brouwer 7bea50b3d9 Rollup merge of #156001 - Human9000-bit:ssa-range-prop-155836, r=dianqk
ssa-range-prop: fix ICE when encountering self-domiating bb

- **Add `strictly_dominates` method**
- **fix ice in ssa-range-prop**

Fixes rust-lang/rust#155836

r? dianqk
2026-05-01 13:10:35 +02:00
Scott McMurray 548cdc1412 Add a Local::arg(i) helper constructor
While reading through stuff I was noticing just how many `+1` fixes there were in various places (and comments explaining that fixup), so this adds a new inherent helper on `Local` for making an argument to help make this clearer.
2026-04-30 20:52:02 -07:00
Nicholas Nethercote bc0e581abf Eliminate IsPrefixOf trait.
It has a single method and a single impl and the trait isn't directly
used. It can just become an inherent method.
2026-05-01 13:32:54 +10:00
Jacob Pratt 96b94a8a52 Rollup merge of #155987 - nnethercote:infallible-Lifting, r=oli-obk
Make lifting infallible

Details in individual commits.

r? @oli-obk
2026-04-30 22:28:33 -04:00
Jacob Pratt 894bdf298e Rollup merge of #155980 - nnethercote:mv-feature-methods, r=TaKO8Ki
Move `feature*` methods from `parse` mod to `errors` mod.

As the FIXME comment says, these no longer use `ParseSess` and so the `parse` mod is not a good place for them. The `errors` mod is a better home.

r? @TaKO8Ki
2026-04-30 22:28:33 -04:00
Nicholas Nethercote ddc626d2e1 Rename KEY type parameters as K.
RFC 430 says type parameters should be named "concise UpperCamelCase,
usually single uppercase letter". So either `Key` or `K` is more
appropriate than `KEY`, which looks like a constant.

I chose `K` because it's a well-known abbreviation of "key" used in lots
of places, e.g. `HashMap<K, V>`.
2026-05-01 08:44:46 +10:00
Nicholas Nethercote c3ceb286fa Remove unused Feed type. 2026-05-01 08:06:07 +10:00
human9000 7b5afc3bf8 Add sctrictly_dominates method 2026-04-30 18:46:11 +05:00
bors f53b654a88 Auto merge of #155018 - nnethercote:simplify-HashStable, r=fee1-dead
Simplify `HashStable`



This PR:
- Simplifies the `HashStable` trait, by moving its generic parameter from the trait to its single method.
- Eliminates the need for the non-obvious `derive(HashStable)`/`derive(HashStable_Generic)` distinction.
- Reduces the need for, and clarifies, the non-obvious `derive(HashStable)`/`derive(HashStable_NoContext)` distinction.

r? @fee1-dead
2026-04-30 07:30:46 +00:00
Nicholas Nethercote a762dbfe76 Make lifting infallible.
Every lifting root calls `unwrap`/`expect` on the result, except for
`ImmTy::fmt` but there's no good reason for that exception. Making
lifting infallible is sensible because it should only fail if the wrong
interner is somehow used, which indicates a major bug in rustc rather
than an error condition.
2026-04-30 16:53:10 +10:00
Nicholas Nethercote ee7e4309be Remove unnecessary lift calls.
Various places where `lift` just isn't necessary. Either because we're
not within a closure passed to `tls::with`, or because the type being lifted
doesn't have a `'tcx` lifetime.
2026-04-30 16:52:17 +10:00
Nicholas Nethercote 6d79bc6f01 Move feature* methods from parse mod to errors mod.
As the FIXME comment says, these no longer use `ParseSess` and so the
`parse` mod is not a good place for them. The `errors` mod is a better
home.
2026-04-30 12:02:33 +10:00
Nicholas Nethercote b7ba58e511 Remove rustc_middle::ich::hcx module.
`rustc_middle::ich` is now just a very thin wrapper around
`rustc_middle::ich::hcx`, so the contents of the latter can be moved
into the former.
2026-04-30 08:26:22 +10:00
Nicholas Nethercote 36c9d23902 Overhaul stable hashing traits.
`std::hash::Hash` looks like this:
```
pub trait Hash {
    fn hash<H>(&self, state: &mut H)
       where H: Hasher;

    ...
}
```
The method is generic.

In contrast, `HashStable` looks like this:
```
pub trait HashStable<Hcx> {
    fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher);
}
```
and impls look like this (in crates upstream of `rustc_middle`):
```
impl<Hcx: HashStableContext> HashStable<Hcx> for Path {
    fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
        ...
    }
}
```
or this (in `rustc_middle` and crates downstream of `rustc_middle`):
```
impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features {
    fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
	...
    }
}
```
Differences to `std::hash::Hash`:
- The trait is generic, rather than the method.
- The way impls are written depends their position in the crate graph.
- This explains why we have both `derive(HashStable)` and
  `derive(HashStable_Generic)`. The former is for the
  downstream-of-`rustc_middle` case, the latter is for the upstream of
  `rustc_middle` case.

Why the differences? It all boils down to `HashStable` and
`HashStableContext` being in different crates. But the previous commit
fixed that, which means `HashStable` can be simplified to this, with a
generic method:
```
pub trait HashStable {
    fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher);
}
```
and all impls look like this:
```
impl HashStable for Path {
    fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
        ...
    }
}
```

Other consequences:
- `derive(HashStable_Generic)` is no longer needed; `derive(HashStable)`
  can be used instead.
  - In this commit, `derive(HashStable_Generic` is made a synonym of
    `derive(HashStable)`. The next commit will remove this synonym,
    because it's a change that touches many lines.
- `#[stable_hash_generic]` is no longer needed (for `newtype_index`);
  `#[stable_hash]` can be used instead.
  - `#[stable_hash_no_context]` was already a synonym of
    `#[stable_hash_generic]`, so it's also removed in favour of just
    `#[stable_hash]`.
- The difference between `derive(HashStable)` and
  `derive(HashStable_NoContext)` now comes down to the difference
  between `synstructure::AddBounds::Generics` and
  `synstructure::AddBounds::Fields`, which is basically "vanilla derive"
  vs "(near) perfect derive".
  - I have improved the comments on `HashStableMode` to better
    explaining this subtle difference.
- `rustc_middle/src/ich/impls_syntax.rs` is no longer needed; the
  relevant impls can be defined in the crate that defines the relevant
  type.
- Occurrences of `for<'a> HashStable<StableHashingContext<'a>>` are
  replaced with with `HashStable`, hooray.
- The commit adds a `HashStableContext::hashing_controls` method, which
  is no big deal. (It's necessary for `AdtDefData::hash_stable`, which
  calls `hashing_controls` and used to have an `hcx` that was a
  concrete `StableHashingContext` but now has an `hcx` that is just
  `Hcx: HashStableContext`.)

Overall this is a big simplification, removing a lot of confusing
complexity in stable hashing traits.
2026-04-30 08:26:19 +10:00
Nicholas Nethercote a6318f677d Move HashStableContext trait to rustc_data_structures.
This puts it in the same crate as the `HashStable` and `ToStableHasher`
traits. This requires introducing three types `RawSpan`, `RawDefId` and
`RawDefPathHash` to work around the fact that `rustc_data_structures`
is upstream of `rustc_span` and so doesn't have access to `Span`,
`DefId`, and `DefPathHash`. This is a bit ugly but is worth it because
moving `HashStableContext` enables big cleanups across many crates in
subsequent commits.
2026-04-30 08:20:37 +10:00
Jonathan Brouwer c208e0e1aa Rollup merge of #155949 - GuillaumeGomez:steal-lints, r=JonathanBrouwer,kivooeo
Update `opt_ast_lowering_delayed_lints` query to allow "stealing" lints, allowing to use `FnOnce` instead of `Fn`

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

This is needed for https://github.com/rust-lang/rust/compare/main...GuillaumeGomez:rust:diagnostic-instead-of-closure?expand=1 which will allow to pass `Diagnostic` instead of a closure.

As asked by @JonathanBrouwer, I make this as a stand-alone PR. :)

r? @JonathanBrouwer
2026-04-29 23:51:41 +02:00
Jonathan Brouwer fb08236a40 Rollup merge of #155794 - SynapLink:share-effective-vis-private-init, r=petrochenkov
privacy: share effective visibility initialization

Address one `FIXME` in `EffectiveVisibilities` by sharing the private effective visibility initialization path between `effective_vis_or_private` and `update`.

`update` now mutates the map entry in place instead of copying the effective visibility out and inserting it back at the end. The inserted default value and update logic are unchanged.

Validation:
- `git diff --check`
- `python x.py check compiler/rustc_middle`
2026-04-29 23:51:32 +02:00
Jonathan Brouwer 6ab97ac1d5 Rollup merge of #155608 - petrochenkov:optmodcmp, r=jdonszelmann
rustc_middle: Implement the `partial_cmp` operation for `DefId`s

And use it in `partial_cmp` implementation for visibilities.
2026-04-29 23:51:31 +02:00
Jonathan Brouwer 5a40d360c7 Rollup merge of #155562 - ChayimFriedman2:no-traits, r=nikomatsakis
Add a missing `GenericTypeVisitable`, and avoid having interner traits for `FnSigKind` and `Abi`

r? types
2026-04-29 23:51:30 +02:00
Vadim Petrochenkov d28ea81a98 resolve: Extend ambiguous_import_visibilities deprecation lint to glob-vs-glob ambiguities 2026-04-29 22:34:16 +03:00
Chayim Refael Friedman dff9d088ab Avoid having traits in rustc_type_ir for FnSigKind and Abi
Instead, just use the concrete types `FnSigKind` and `rustc_abi::ExternAbi`. This simplifies the code in both rustc and rust-analyzer.
2026-04-29 20:19:26 +03:00
Vadim Petrochenkov 66202c82d7 rustc_middle: Implement the partial_cmp operation for DefIds
And use it in `partial_cmp` implementation for visibilities
2026-04-29 17:09:03 +03:00
SynapLink 89e272ce7b privacy: share effective visibility initialization 2026-04-29 09:57:26 +02:00
Guillaume Gomez fffc4b5781 Update opt_ast_lowering_delayed_lints query to allow "stealing" lints, allowing to use FnOnce instead of Fn 2026-04-29 01:21:54 +02:00
Jonathan Brouwer 22967dff41 Rollup merge of #155273 - zetanumbers:create_crate_num_lock, r=jdonszelmann
Lock stable_crate_ids once in create_crate_num

This is a small refactor PR removing redundant locks of `stable_crate_ids` from  `create_crate_num`.
2026-04-28 20:24:32 +02:00
Nicholas Nethercote d06d50c4ba Rename some session variables from s to sess.
Because `sess` is the standard name.
2026-04-28 22:12:44 +10:00
Nicholas Nethercote cbf22e6b3c Wrap some overlong comments. 2026-04-28 22:12:20 +10:00
bors 4ddb0b7f8e Auto merge of #155329 - nnethercote:rm-WithCachedTypeInfo-stable_hash, r=oli-obk
Remove `WithCachedTypeInfo::stable_hash`.



We store a stable hash value in the most common interned values (e.g. types, predicates, regions). This is 16 bytes of data.
- In non-incremental builds it's a straightforward performance loss: the stable hash isn't computed or used, and the 16 bytes of space goes to waste (but it still gets hashed when interning).
- In incremental builds it avoids some hashing but doesn't seem to actually be a genuine performance win, and the complexity doesn't seem worth it.

r? @oli-obk
2026-04-28 07:33:06 +00:00
Jonathan Brouwer e8ad7f25e4 Rollup merge of #155702 - mejrs:itemkind_trait-fields, r=petrochenkov
Change `ItemKind::Trait` to a field variant.

This changes `ItemKind::Trait` from an octuple(!!) to an enum variant with fields. Their names were chosen to match up with existing usage and minimize renaming.

I'm leaning towards renaming `ident` to `name` as well; let me know if that's desired.
2026-04-27 19:54:46 +02:00
Jacob Pratt 6897624a46 Rollup merge of #155772 - oli-obk:const-closures-everywhere, r=fee1-dead
Check closure's constness validity in the constness query

fixes rust-lang/rust#155584

instead of checking during ast lowering, where it's not easily possible to obtain all the right information in time. While lowering an assoc item we don't know if the parent was a const trait or a const impl. Tracing this information is quite annoying, and complicates a lot of code, which checking here after the fact is trivial.
2026-04-27 03:48:43 -04:00
Oli Scherer 8e1c34f5cc Check closure's constness validity in the constness query
instead of during ast lowering, where it's not easily possible to obtain all the right information in time
2026-04-27 07:44:19 +02:00
Jacob Pratt bd2d1a8443 Rollup merge of #155835 - jyn514:jyn/verify-ich-diagnostics, r=wesleywiser
couple of `crate_name` cleanups

Split out from https://github.com/rust-lang/rust/pull/153924; these changes should be uncontroversial.
2026-04-26 21:56:46 -04:00
Jacob Pratt c20a92efd9 Rollup merge of #155778 - kevinheavey:perf-mk-place-elem-avoid-vec-alloc, r=cjgillot,JohnTitor
Avoid Vec allocation in TyCtxt::mk_place_elem

`mk_place_elem` appends a single `PlaceElem` to an existing (interned) projection. The current implementation copies the projection into a fresh `Vec`, pushes the new element, and re-interns the slice, which allocates on every call.

Feed the elements through `mk_place_elems_from_iter` so that `CollectAndApply`'s hand-unrolled stack fast path (up to 9 elements, in `rustc_type_ir::interner`) kicks in for the common case of short projections and the `Vec` allocation is skipped entirely. The behavior is identical for longer projections (the fast path falls back to a `Vec` internally).
2026-04-26 21:56:42 -04:00