2457 Commits

Author SHA1 Message Date
Jonathan Brouwer dde4886801 Rollup merge of #146181 - Flakebi:dynamic-shared-memory, r=ZuseZ4,Sa4dus,workingjubilee,RalfJung,nikic,kjetilkjeka,kulst
Add intrinsic for launch-sized workgroup memory on GPUs

Workgroup memory is a memory region that is shared between all
threads in a workgroup on GPUs. Workgroup memory can be allocated
statically or after compilation, when launching a gpu-kernel.
The intrinsic added here returns the pointer to the memory that is
allocated at launch-time.

# Interface

With this change, workgroup memory can be accessed in Rust by
calling the new `gpu_launch_sized_workgroup_mem<T>() -> *mut T`
intrinsic.

It returns the pointer to workgroup memory guaranteeing that it is
aligned to at least the alignment of `T`.
The pointer is dereferencable for the size specified when launching the
current gpu-kernel (which may be the size of `T` but can also be larger
or smaller or zero).

All calls to this intrinsic return a pointer to the same address.

See the intrinsic documentation for more details.

## Alternative Interfaces

It was also considered to expose dynamic workgroup memory as extern
static variables in Rust, like they are represented in LLVM IR.
However, due to the pointer not being guaranteed to be dereferencable
(that depends on the allocated size at runtime), such a global must be
zero-sized, which makes global variables a bad fit.

# Implementation Details

Workgroup memory in amdgpu and nvptx lives in address space 3.
Workgroup memory from a launch is implemented by creating an
external global variable in address space 3. The global is declared with
size 0, as the actual size is only known at runtime. It is defined
behavior in LLVM to access an external global outside the defined size.

There is no similar way to get the allocated size of launch-sized
workgroup memory on amdgpu an nvptx, so users have to pass this
out-of-band or rely on target specific ways for now.

Tracking issue: rust-lang/rust#135516
2026-04-25 23:07:48 +02:00
Flakebi 13ec3de673 Add intrinsic for launch-sized workgroup memory on GPUs
Workgroup memory is a memory region that is shared between all
threads in a workgroup on GPUs. Workgroup memory can be allocated
statically or after compilation, when launching a gpu-kernel.
The intrinsic added here returns the pointer to the memory that is
allocated at launch-time.

# Interface

With this change, workgroup memory can be accessed in Rust by
calling the new `gpu_launch_sized_workgroup_mem<T>() -> *mut T`
intrinsic.

It returns the pointer to workgroup memory guaranteeing that it is
aligned to at least the alignment of `T`.
The pointer is dereferencable for the size specified when launching the
current gpu-kernel (which may be the size of `T` but can also be larger
or smaller or zero).

All calls to this intrinsic return a pointer to the same address.

See the intrinsic documentation for more details.

## Alternative Interfaces

It was also considered to expose dynamic workgroup memory as extern
static variables in Rust, like they are represented in LLVM IR.
However, due to the pointer not being guaranteed to be dereferencable
(that depends on the allocated size at runtime), such a global must be
zero-sized, which makes global variables a bad fit.

# Implementation Details

Workgroup memory in amdgpu and nvptx lives in address space 3.
Workgroup memory from a launch is implemented by creating an
external global variable in address space 3. The global is declared with
size 0, as the actual size is only known at runtime. It is defined
behavior in LLVM to access an external global outside the defined size.

There is no similar way to get the allocated size of launch-sized
workgroup memory on amdgpu an nvptx, so users have to pass this
out-of-band or rely on target specific ways for now.
2026-04-24 10:03:45 +02:00
yukang 8d75f0cbfc add on_unmatch_args 2026-04-22 19:28:44 +08:00
bors 27dbdb57a2 Auto merge of #155416 - Zalathar:rollup-D1EWnrR, r=Zalathar
Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#141633 (Suggest to bind `self.x` to `x` when field `x` may be in format string)
 - rust-lang/rust#152980 (c-variadic: fix implementation on `avr`)
 - rust-lang/rust#154491 (Extend `core::char`'s documentation of casing issues (and fix a rustdoc bug))
 - rust-lang/rust#155318 (Use mutable pointers for Unix path buffers)
 - rust-lang/rust#155335 (Bump bootstrap to 1.96 beta)
 - rust-lang/rust#155354 (Remove AttributeSafety from BUILTIN_ATTRIBUTES)
 - rust-lang/rust#154970 (rustdoc: preserve `doc(cfg)` on locally re-exported type aliases)
 - rust-lang/rust#155095 (changed the information provided by (mut x) to mut x (Fix 155030))
 - rust-lang/rust#155305 (Make `convert_while_ascii` unsafe)
 - rust-lang/rust#155358 (ImproperCTypes: Move erasing_region_normalisation into helper function)
 - rust-lang/rust#155377 (tests/debuginfo/basic-stepping.rs: Remove FIXME related to ZSTs)
 - rust-lang/rust#155383 (Rearrange `rustc_ast_pretty`)
 - rust-lang/rust#155384 (triagebot: notify on diagnostic attribute changes)
 - rust-lang/rust#155386 (Use `box_new` diagnostic item for Box::new suggestions)
 - rust-lang/rust#155391 (Small refactor of `QueryJob::latch` method)
 - rust-lang/rust#155395 (Tweak how the "copy path" rustdoc button works to allow some accessibility tool to work with rustdoc)
 - rust-lang/rust#155396 (`as_ref_unchecked` docs link fix)
 - rust-lang/rust#155411 (compiletest: Remove the `//@ should-ice` directive)
 - rust-lang/rust#155413 (fix: typo in `std::fs::hard_link` documentation)
2026-04-17 07:35:43 +00:00
Stuart Cook 91a7d1b498 Rollup merge of #152980 - folkertdev:c-variadic-avr, r=tgross35
c-variadic: fix implementation on `avr`

tracking issue: https://github.com/rust-lang/rust/issues/44930
cc target maintainer @Patryk27

I ran into multiple issues, and although with this PR and a little harness I can run the test with qemu on avr, the implementation is perhaps not ideal.

The problem we found is that on `avr` the `c_int/c_uint` types are `i16/u16`, and this was not handled in the c-variadic checks. Luckily there is a field in the target configuration that contains the targets `c_int_width`. However, this field is not actually used in `core` at all, there the 16-bit targets are just hardcoded.

https://github.com/rust-lang/rust/blob/1500f0f47f5fe8ddcd6528f6c6c031b210b4eac5/library/core/src/ffi/primitives.rs#L174-L185

Perhaps we should expose this like endianness and pointer width?

---

Finally there are some changes to the test to make it compile with `no_std`.
2026-04-17 16:17:50 +10:00
Dominik Schwaiger da2bbfbbec add llvm writable attribute conditionally 2026-04-16 12:29:39 +00:00
Folkert de Vries a875e140b6 c-variadic: make VaArgSafe a lang item
so that we can check whether a type implements the trait
2026-04-16 11:48:06 +02:00
Jonathan Brouwer b7286260c8 Rollup merge of #155235 - folkertdev:fma4-target-feature, r=sayantn
add the `fma4` x86 target feature

tracking issue: https://github.com/rust-lang/rust/issues/155233

Implications are based on LLVM

https://github.com/llvm/llvm-project/blob/df6c82053c5e1f9814d130d423f34871bc6423c5/llvm/lib/Target/X86/X86.td#L201-L206

This feature adds a slightly better instruction encoding for fma. We might want to expose the intrinsics in `stdarch` with that target feature, but just adding the target feature in user code should already take advantage of this improved encoding.

This target feature is used in `libm`.

r? sayantn
2026-04-14 16:29:33 +02:00
Folkert de Vries c766242209 add the fma4 x86 target feature 2026-04-13 14:12:08 +02:00
Jonathan Brouwer d4037f7d8f Rollup merge of #153335 - Ozzy1423:removed-features, r=jdonszelmann
Add #![unstable_removed(..)] attribute to track removed features

Adds the #![unstable_removed(..)] attribute to enable tracking removed library features.
Produce an error when a removed attribute is used.
Add a test that it works.

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

r? @jyn514
2026-04-13 14:02:30 +02:00
Jonathan Brouwer 2834b1654a Rollup merge of #155068 - lapla-cogito:multibyte_char, r=mati865
Fix ICE in `span_extend_prev_while` with multibyte characters

Fixes https://github.com/rust-lang/rust/issues/155037

The function assumed that the character found by `rfind` was always one byte wide, using a hardcoded `1` instead of `c.len_utf8()`. When a multibyte character appeared immediately before the span, this caused the resulting span to point into the middle of a UTF-8 sequence, triggering an assertion failure in `bytepos_to_file_charpos`.
2026-04-12 15:44:20 +02:00
Oscar Bray 25a92d208d Add #![unstable_removed(..)] attribute to track removed features
Move concat_idents to use the unstable_removed attribute
2026-04-12 11:18:10 +01:00
Folkert de Vries 6bcd172f5a add cfg(target_object_format = "...") 2026-04-11 14:12:39 +02:00
bors 02c7f9bec0 Auto merge of #155115 - JonathanBrouwer:rollup-RePrRPQ, r=JonathanBrouwer
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#152901 (Introduce a `#[diagnostic::on_unknown]` attribute)
 - rust-lang/rust#155078 (Reject dangling attributes in where clauses)
 - rust-lang/rust#154449 (Invert dependency between `rustc_errors` and `rustc_abi`.)
 - rust-lang/rust#154646 (Add suggestion to `.to_owned()` used on `Cow` when borrowing)
 - rust-lang/rust#154993 (compiletest: pass -Zunstable-options for unpretty and no-codegen paths)
 - rust-lang/rust#155097 (Make `rustc_attr_parsing::SharedContext::emit_lint` take a `MultiSpan` instead of a `Span`)
2026-04-10 18:19:03 +00:00
Jonathan Brouwer 9c01701171 Rollup merge of #154646 - m4rch3n1ng:144792-cow-diag, r=davidtwco
Add suggestion to `.to_owned()` used on `Cow` when borrowing

fixes rust-lang/rust#144792
supersedes rust-lang/rust#144925 with the review comments addressed

the tests suggested from @Kivooeo from https://github.com/rust-lang/rust/pull/144925#discussion_r2252703007 didn't work entirely, because these tests failed due to error `[E0308]` mismatched types, which actually already provides a suggestion, that actually makes the code compile:

```
$ cargo check
error[E0308]: mismatched types
 --> src/main.rs:3:5
  |
1 | fn test_cow_suggestion() -> String {
  |                             ------ expected `std::string::String` because of return type
2 |     let os_string = std::ffi::OsString::from("test");
3 |     os_string.to_string_lossy().to_owned()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `Cow<'_, str>`
  |
  = note: expected struct `std::string::String`
               found enum `std::borrow::Cow<'_, str>`
help: try using a conversion method
  |
3 |     os_string.to_string_lossy().to_owned().to_string()
  |                                           ++++++++++++
```

now this suggestion is of course not good or efficient code, but via clippy with `-Wclippy::nursery` lint group you can actually get to the correct code, so i don't think this is too much of an issue:

<details>
<summary>the clippy suggestions</summary>

```
$ cargo clippy -- -Wclippy::nursery
warning: this `to_owned` call clones the `Cow<'_, str>` itself and does not cause its contents to become owned
 --> src/main.rs:3:5
  |
3 |     os_string.to_string_lossy().to_owned().to_string()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/beta/index.html#suspicious_to_owned
  = note: `#[warn(clippy::suspicious_to_owned)]` on by default
help: depending on intent, either make the `Cow` an `Owned` variant
  |
3 |     os_string.to_string_lossy().into_owned().to_string()
  |                                 ++
help: or clone the `Cow` itself
  |
3 -     os_string.to_string_lossy().to_owned().to_string()
3 +     os_string.to_string_lossy().clone().to_string()
  |
$ # apply first suggestion
$ cargo c -- -Wclippy::nursery
warning: redundant clone
 --> src/main.rs:3:45
  |
3 |     os_string.to_string_lossy().into_owned().to_string()
  |                                             ^^^^^^^^^^^^ help: remove this
  |
note: this value is dropped without further use
 --> src/main.rs:3:5
  |
3 |     os_string.to_string_lossy().into_owned().to_string()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/beta/index.html#redundant_clone
  = note: `-W clippy::redundant-clone` implied by `-W clippy::nursery`
  = help: to override `-W clippy::nursery` add `#[allow(clippy::redundant_clone)]`
```

</details>

the actual error that we are looking for is error `[E0515]`, cannot return value referencing local variable, which was only present in the original issue due to automatic type inference assuming you want to return a cloned `Cow<'_, str>`, which is of course not possible. this is why i took the original test functions and turned them into closures, where it's less obvious that it's trying to return the wrong type.

r? davidtwco

(because you reviewed the last attempt)
(also, let me know if i should squash this down to one commit and add myself as the co-contributor)
2026-04-10 18:38:14 +02:00
Jonathan Brouwer 6547a33a8b Rollup merge of #155027 - fmease:more-test-attr-renamings, r=JonathanBrouwer
Rename some more of our internal `#[rustc_*]` TEST attributes

Follow-up to https://github.com/rust-lang/rust/pull/153300.

r? JonathanBrouwer or jdonszelmann
2026-04-10 15:33:13 +02:00
León Orell Valerian Liehr cb4a7f4f19 Rename #[rustc_symbol_name] to #[rustc_dump_symbol_name] 2026-04-10 12:14:39 +02:00
León Orell Valerian Liehr 0a597064ba Rename #[rustc_def_path] to #[rustc_dump_def_path] 2026-04-10 12:14:23 +02:00
León Orell Valerian Liehr dda1ea0c43 Rename #[rustc_hidden_type_of_opaques] to #[rustc_dump_hidden_type_of_opaques] 2026-04-10 12:14:07 +02:00
León Orell Valerian Liehr 7025605b8c Rename #[rustc_dump_layout]'s abi option to backend_repr
Moreover, dereference `ty_layout.align` for `#[rustc_dump_layout(align)]`
to render `align: Align($N bytes)` instead of `align: AbiAlign { abi: Align($N bytes) }`
which contains the same amount of information but it more concise and legible.
2026-04-10 12:13:52 +02:00
León Orell Valerian Liehr 357f670fde Rename #[rustc_layout] to #[rustc_dump_layout] 2026-04-10 12:13:48 +02:00
Jana Dönszelmann 2facd34bc8 add #[rustc_must_match_exhaustively] 2026-04-10 11:43:27 +02:00
Georg Semmler 97da8195de Rename the attribute to on_unknown 2026-04-10 09:01:20 +02:00
Georg Semmler 6e5fc9075c Introduce a #[diagnostic::on_unknown_item] attribute
This PR introduces a `#[diagnostic::on_unknown_item]` attribute that
allows crate authors to customize the error messages emitted by
unresolved imports. The main usecase for this is using this attribute as
part of a proc macro that expects a certain external module structure to
exist or certain dependencies to be there.

For me personally the motivating use-case are several derives in diesel,
that expect to refer to a `tabe` module. That is done either
implicitly (via the name of the type with the derive) or explicitly by
the user. This attribute would allow us to improve the error message in
both cases:

* For the implicit case we could explicity call out our
assumptions (turning the name into lower case, adding an `s` in the end)
+ point to the explicit variant as alternative
* For the explicit variant we would add additional notes to tell the
user why this is happening and what they should look for to fix the
problem (be more explicit about certain diesel specific assumptions of
the module structure)

I assume that similar use-cases exist for other proc-macros as well,
therefore I decided to put in the work implementing this new attribute.
I would also assume that this is likely not useful for std-lib internal
usage.
2026-04-10 08:55:02 +02:00
lapla 2754a83cc6 Fix ICE in span_extend_prev_while with multibyte characters 2026-04-10 06:34:12 +09:00
Jonathan Brouwer 65745a1b95 Revert #152369 because of multiple regressions
The regressions are documented in the PR comments.
This reverts commit 2972b5e, reversing changes made to f908263.
2026-04-09 18:53:59 +02:00
Jonathan Brouwer 83e81337ad Rollup merge of #154893 - jdonszelmann:expected-literal-positive, r=JonathanBrouwer
make `expected_literal` positive

r? @JonathanBrouwer
2026-04-08 23:04:36 +02:00
Jonathan Brouwer 3fb712c80a Rollup merge of #154719 - androm3da:hexagon-inline-asm-register-classes, r=JohnTitor
Hexagon inline asm: add reg_pair, vreg, vreg_pair, and qreg register classes

Add three new register classes for the Hexagon inline assembly backend:

* `reg_pair`: GPR double registers (r1:0 through r27:26)
* `vreg`: HVX vector registers (v0-v31)
* `qreg`: HVX predicate registers (q0-q3), clobber-only for now
2026-04-08 23:04:34 +02:00
Jana Dönszelmann 1e8c6f04d4 Nooooo my workflow relied on programs using niko as an identifier
being faster to compile 😭
2026-04-08 16:17:27 +02:00
yukang ef9b7c2b8f replace span_look_ahead with span_followed_by 2026-04-08 09:34:24 +08:00
Brian Cain aa9da4b859 Hexagon inline asm: add reg_pair, vreg, vreg_pair, and qreg register classes
Add new Hexagon inline asm register classes:
- reg_pair: GPR double registers (r1:0 through r27:26) for i64/f64 types
- vreg: HVX vector registers (v0-v31) for mode-dependent vector types
- vreg_pair: HVX vector pair registers (v1:0 through v31:30) for vector pairs
- qreg: HVX predicate registers (q0-q3), clobber-only

Key implementation details:
- GPR pairs use LLVM's 'd' register naming (d0-d13) for constraints
- HVX vector pairs use LLVM's 'w' register naming (w0-w15) for constraints
- Register overlap tracking for GPR pair<->single and HVX pair<->single conflicts
- HVX vector types are mode-dependent (64B vs 128B HVX length)

Note: vreg_quad (HVX vector quads) is not supported as LLVM's Hexagon
backend does not support vector quad types in inline asm constraints.
2026-04-07 09:27:32 -07:00
Jacob Pratt 24223a62ae Rollup merge of #154744 - nnethercote:rm-Clone-for-StableHashingContext, r=fee1-dead
Remove `Clone` impl for `StableHashingContext`.

`HashStable::hash_stable` takes a `&mut Hcx`. In contrast, `ToStableHashKey::to_stable_hash_key` takes a `&Hcx`. But there are some places where the latter calls the former, and due to the mismatch a `clone` call is required to get a mutable `StableHashingContext`.

This commit changes `to_stable_hash_key` to instead take a `&mut Hcx`. This eliminates the mismatch, the need for the clones, and the need for the `Clone` impls.

r? @fee1-dead
2026-04-05 20:51:06 -04:00
Matthias Krüger dd46057276 Rollup merge of #154653 - mejrs:append_const_msg, r=JonathanBrouwer
Remove rustc_on_unimplemented's append_const_msg

This does nothing because it is unreachable within the compiler. It also doesn't seem that useful since all the traits it was on are `const` now.

Will make pr to rustc-dev-guide docs later.
2026-04-03 20:47:38 +02:00
Matthias Krüger a4d278d889 Rollup merge of #153592 - zedddie:adt_const_params_restricted_privacy-gate, r=BoxyUwU
Add  `min_adt_const_params` gate

Add `min_adt_const_params` feature gate to disallow `ConstParamTy_` impl for types which fields visibility mismatches with struct itself

r? BoxyUwU
2026-04-03 20:47:37 +02:00
Matthias Krüger 6d6e0ae02d Rollup merge of #153286 - davidtwco:sve-intrinsics, r=Amanieu
various fixes for scalable vectors

These are a handful of patches fixing bugs with the current `#[rustc_scalable_vector]` infrastructure so that we can upstream the intrinsics to stdarch:

1. Instead of just using regular struct lowering for tuples of scalable vectors, which results in an incorrect ABI (e.g. returning indirectly), we change to using `BackendRepr::ScalableVector` which will lower to the correct type and be passed in registers.
2. Clang changed from representing tuples of scalable vectors as structs rather than as wide vectors (that is, scalable vector types where the `N` part of the `<vscale x N x ty>` type was multiplied by the number of vectors). rustc mirrored this in the initial implementation of scalable vectors that didn't land.

   When our early patches used the wide vector representation, our intrinsic patches used the legacy `llvm.aarch64.sve.tuple.{create,get,set}{2,3,4}` intrinsics for creating these tuples/getting/setting the vectors, which were only supported due to LLVM's `AutoUpgrade` pass converting these intrinsics into `llvm.vector.insert`. `AutoUpgrade` only supports these legacy intrinsics with the wide vector representation.

   With the current struct representation, Clang has special handling in codegen for generating `insertvalue`/`extractvalue` instructions for these operations, which must be replicated by rustc's codegen for our intrinsics to use.

   We add a new `core::intrinsics::scalable` module (never intended to be stable, just used by the stdarch intrinsics, gated by `core_intrinsics`) and add new intrinsics which rustc lowers to the appropriate `insertvalue`/`extractvalue` instructions.
3. Add generation of debuginfo for scalable vectors, following the DWARF that Clang generates.
4. Some intrinsics need something like `simd_cast`, which will work for scalable vectors too, so this implements a new `sve_cast` intrinsic that uses the same internals as `simd_cast`. This seemed better than permitting scalable vectors to be used with the `simd_*` intrinsics more generally as I can't guarantee this would work for all of them.

This is a relatively large patch but most of it is tests, and each commit should be relatively standalone. It's a little bit easier to upstream them together to avoid needing to stack them.  It's possible that some more compiler fixes will be forthcoming but it's looking like this might be all at the moment.

Depends on rust-lang/rust#153653

r? @workingjubilee (discussed on Zulip)
2026-04-03 20:47:36 +02:00
David Wood 957320cdb1 cg_llvm: sve_cast intrinsic
Abstract over the existing `simd_cast` intrinsic to implement a new
`sve_cast` intrinsic - this is better than allowing scalable vectors to
be used with all of the generic `simd_*` intrinsics.
2026-04-03 10:37:42 +00:00
David Wood 4fbcb031de cg_llvm: sve_tuple_{create,get,set} intrinsics
Clang changed to representing tuples of scalable vectors as
structs rather than as wide vectors (that is, scalable vector types
where the `N` part of the `<vscale x N x ty>` type was multiplied by
the number of vectors). rustc mirrored this in the initial implementation
of scalable vectors.

Earlier versions of our patches used the wide vector representation and
our intrinsic patches used the legacy
`llvm.aarch64.sve.tuple.{create,get,set}{2,3,4}` intrinsics for creating
these tuples/getting/setting the vectors, which were only supported
due to LLVM's `AutoUpgrade` pass converting these intrinsics into
`llvm.vector.insert`. `AutoUpgrade` only supports these legacy intrinsics
with the wide vector representation.

With the current struct representation, Clang has special handling in
codegen for generating `insertvalue`/`extractvalue` instructions for
these operations, which must be replicated by rustc's codegen for our
intrinsics to use. This patch implements new intrinsics in
`core::intrinsics::scalable` (mirroring the structure of
`core::intrinsics::simd`) which rustc lowers to the appropriate
`insertvalue`/`extractvalue` instructions.
2026-04-03 10:27:30 +00:00
Jonathan Brouwer ce7c492589 fix rebase 2026-04-03 11:12:15 +02:00
Nicholas Nethercote ff1795fe49 Remove Clone impl for StableHashingContext.
`HashStable::hash_stable` takes a `&mut Hcx`. In contrast,
`ToStableHashKey::to_stable_hash_key` takes a `&Hcx`. But there are
some places where the latter calls the former, and due to the mismatch a
`clone` call is required to get a mutable `StableHashingContext`.

This commit changes `to_stable_hash_key` to instead take a `&mut Hcx`.
This eliminates the mismatch, the need for the clones, and the need for
the `Clone` impls.
2026-04-03 15:34:33 +11:00
Jonathan Brouwer 483dc59aa2 Rollup merge of #154710 - khyperia:rename-ogca, r=BoxyUwU
opaque_generic_const_args -> generic_const_args

This is part of a larger rework/plan of how to move forward with GCA. Please comment here, or message/ping me or @BoxyUwU if you have questions about the future of oGCA/GCA!

For ease of review, the first commit is renaming, and the second commit is removing the opaque parts.

fyi @camelid

r? @BoxyUwU
2026-04-02 22:13:51 +02:00
Jonathan Brouwer c43a549505 Rollup merge of #154666 - nnethercote:rm-StableHashContext-impls, r=petrochenkov
Remove `StableHashContext` impls

Details in individual commits.

r? @petrochenkov
2026-04-02 22:13:50 +02:00
zedddie 72fbd1c0b5 implement min_adt_const_params feature 2026-04-02 17:10:41 +02:00
khyperia 0e2c554e74 rename opaque_generic_const_args to generic_const_args 2026-04-02 12:04:25 +02:00
bors 8931f23941 Auto merge of #154614 - nnethercote:streamline-CachingSourceMapView, r=JonathanBrouwer
Streamline `CachingSourceMapView`

`CachingSourceMapView` is home to some pretty ugly, low-level, repetitive code. We can do better. Details in individual commits.

r? @JonathanBrouwer
2026-04-02 03:18:50 +00: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
Nicholas Nethercote 919c632c0e Streamline CachingSourceMapView.
`CachingSourceMapView` caches information about three recent code
positions, to avoid expensive `SourceMap` lookups. The code to do this
is pretty low-level and grotty.

This commit changes it to cache information about a single code
position.
- This is much simpler, with no need to maintain entry time stamps or
  file indices. It's 120 fewer lines of code overall.
- It's also faster. The cache hit rate is only marginally lower, and
  scanning a single entry is faster than scanning three entries in the
  cache miss case (which is still moderately common).

The commit also renames the `lines` field as `line_bounds`, which makes
it clearer that it's a range.
2026-04-01 06:34:55 +11:00
Nicholas Nethercote c30f5cb084 Refactor byte_pos_to_line_and_col.
By factoring out some repeated code.
2026-04-01 06:34:54 +11:00
Nicholas Nethercote 0eea36fea4 Use Option to indicate failure in CachingSourceMapView.
Currently the `cache_entry_index` uses -1 to indicate failure. But this
is Rust, not C! So this commit uses `Option`, making it impossible to
forget to check for failure, and avoiding many `as usize` casts.
2026-04-01 06:34:31 +11:00
may 41f7c2d4e2 apply review suggestions and move Cow sym to rustc 2026-03-31 21:32:31 +02:00
mejrs 70dd3bceca Remove rustc_on_unimplemented's append_const_msg 2026-03-31 20:46:21 +02:00