10586 Commits

Author SHA1 Message Date
Jonathan Brouwer 2e9a40258c Rollup merge of #155957 - oli-obk:const-closure-std, r=jhpratt
Revert const hacks and use const closures in std

This revealed some smaller bugs in stability checking that I fixed where needed:

* const closures use the const stability of their parent
* trait method default bodies use the const stability of their trait

Otherwise trivial reverts of the const hacks that were added

fixes rust-lang/rust#155781
2026-05-05 14:25:25 +02:00
Oli Scherer a015eb119a Revert const hack and use const closure 2026-05-05 11:36:18 +02:00
Oli Scherer 664177fdf1 Remove const closure hacks in libstd 2026-05-05 11:35:29 +02:00
Guillaume Gomez ca222b85ff Rollup merge of #156104 - aobatact:try-as-dyn-unsized, r=oli-obk
Relax `T: Sized` bound on `try_as_dyn` / `try_as_dyn_mut`

`trait_info_of` already returns `None` for unsized types, so allowing `T: ?Sized` is sound and lets callers in generic contexts use these functions without a separate `Sized` bound. For unsized `T`, the function always returns `None`.

Tracking issue: rust-lang/rust#144361

## Motivation

Currently, it is not possible to use `try_as_dyn` as "specialization-like" dispatch in
blanket impls with `?Sized` type.

```rust
// Cannot add ?Sized now.
impl<T: 'static /* + ?Sized */, S: Serializer + 'static> Serialize<S> for T {
    fn serialize(&self, serializer: &mut S) -> Result<S::Ok, S::Error> {
        if let Some(spec) = try_as_dyn::<_, dyn SpecializedSer<S>>(self) {
            spec.specialized_serialize(serializer)
        } else {
            // fall back to compile-time reflection via TypeId
            ...
        }
    }
}
```
2026-05-05 02:50:12 +02:00
Guillaume Gomez 6b750498bc Rollup merge of #155855 - ChrisDenton:remove-unsafe-get, r=Mark-Simulacrum
Remove unnecessary `get_unchecked`

My benchmarking did not show any issue with using the safe method instead so I assume this isn't an issue any more. But let's do a perf run to be sure.
2026-05-05 02:50:07 +02:00
Guillaume Gomez 6c103078ab Rollup merge of #155848 - bushrat011899:revert_08bd077, r=Mark-Simulacrum
[doc]: Revert `core::io::ErrorKind` doc changes

ACP: https://github.com/rust-lang/libs-team/issues/755
Tracking issue: https://github.com/rust-lang/rust/issues/154046
Related: https://github.com/rust-lang/rust/pull/154654

## Description

rust-lang/rust#154654 changed the documentation for `ErrorKind` to remove links to `std` items. These changes were made falsely assuming documentation links from `core` to `std` were not possible. Since it is possible, we can restore the documentation to its original form prior to the `core::io` move.

## Notes

* No AI tooling of any kind was used in the creation of this PR.
2026-05-05 02:50:06 +02:00
bors ad3a598ca4 Auto merge of #156113 - JonathanBrouwer:rollup-yXpNY1L, r=JonathanBrouwer
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#153536 (Add `const_param_ty_unchecked` gate)
 - rust-lang/rust#155528 (const-stabilize `char::is_control()`)
 - rust-lang/rust#156086 (VaList::next_arg: track_caller for better Miri errors)
2026-05-03 17:54:12 +00:00
Jonathan Brouwer 06354f4e17 Rollup merge of #156086 - RalfJung:next-arg-miri-errs, r=folkertdev
VaList::next_arg: track_caller for better Miri errors

The test diff should explain why this is better. :)

r? @folkertdev
2026-05-03 19:23:53 +02:00
Jonathan Brouwer b8c24b1d4f Rollup merge of #155528 - Jules-Bertholet:const-is-control, r=folkertdev
const-stabilize `char::is_control()`
2026-05-03 19:23:52 +02:00
aobatact ecf527faaf Relax T: Sized bound on try_as_dyn / try_as_dyn_mut
`trait_info_of` already returns `None` for unsized types, so allowing
`T: ?Sized` is sound and lets callers in generic contexts use these
functions without a separate `Sized` bound. For unsized `T`, the
function always returns `None`.
2026-05-03 23:00:31 +09:00
Josh Triplett df8a13ecf4 Hand-implement impl Debug for NumBuffer to avoid constraining T or printing MaybeUninit
The derived implementation requires `T: Debug`, and doesn't need to.
2026-05-02 22:47:13 -07:00
Ralf Jung e402c1edf0 miri: remove retag statements, make typed copies retag implicitly instead 2026-05-02 17:40:33 +02:00
Ralf Jung 9cdf5dc515 VaList::next_arg: track_caller for better Miri errors 2026-05-02 14:33:04 +02:00
Folkert de Vries ba9444c4f4 c-variadic: test that const and mutable void and char pointers implement VaArgSafe 2026-04-30 20:09:52 +02:00
Folkert de Vries ab19cd3dea c-variadic: add a Copy bound to VaArgSafe
because a VaList can be cloned, the same c-variadic argument can be read twice and that is only safe if the argument type is copy
2026-04-30 20:09:51 +02:00
Folkert de Vries eb8f85e7f4 c-variadic: document Clone and Drop instances 2026-04-30 20:09:51 +02:00
Jonathan Brouwer 416d0bf523 Rollup merge of #155832 - folkertdev:c-variadic-ub-check, r=RalfJung
c-variadic: more precise compatibility check in const-eval

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

This came up in the stabilization report discussion https://github.com/rust-lang/rust/pull/155697#discussion_r3139778447.

As a reminder, this is what C says (in section 7.16.1.1 of the [C23 standard](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf#page=302).

> If type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), the behavior is undefined, except for the following cases:
>
> -  both types are pointers to qualified or unqualified versions of compatible types;
>  - one type is compatible with a signed integer type, the other type is compatible with the
>  corresponding unsigned integer type, and the value is representable in both types;
>  - one type is pointer to qualified or unqualified void and the other is a pointer to a qualified or
>  unqualified character type;
>  - or, the type of the next argument is `nullptr_t` and type is a pointer type that has the same representation and alignment requirements as a pointer to a character type

I think the last rule is not relevant for us, we don't really have an equivalent of `nullptr_t` as far as I know.

r? RalfJung
cc @tgross35
2026-04-29 23:51:33 +02:00
Folkert de Vries c560774cf3 c-variadic: more precise compatibility check in const-eval 2026-04-29 17:45:39 +02:00
Ralf Jung ad7ddbc08e simd_reduce_min/max: remove float support 2026-04-29 13:48:45 +02:00
Shoyu Vanilla (Flint) 44753d47a5 Rollup merge of #155943 - romancitodev:fix/version-mismatch, r=nia-e
fix: ✏️ forgot to change the stable version for `assert_matches!` macro.

The `assert_matches` macro was delayed because of rust-lang/rust#154406 and the `#[stable(since)]` wasn't changed to the next version.
2026-04-29 10:40:48 +09:00
romandev 910e2d2cd0 fix: adding missing corrections 2026-04-28 16:59:56 -03:00
romandev a449ea5ee6 fix: ✏️ forgot to change the stable version for assert_matches! macro. 2026-04-28 16:32:55 -03:00
Jonathan Brouwer 766d9caf51 Rollup merge of #155913 - mejrs:delete_the_fixme, r=nia-e
Delete the 12 year old fixme

I think Option is documented well enough at this point.
2026-04-28 20:24:37 +02:00
Jonathan Brouwer 8f15da4d30 Rollup merge of #155361 - Darksonn:abi-cfi, r=RalfJung
Document that CFI diverges from Rust wrt. ABI-compatibility rules

The CFI sanitizer is a sanitizer that checks that no ABI-incompatible function calls are made at runtime, but there is currently an unfortunate divergence between the Rust ABI-compatibility rules and what the CFI sanitizer checks. Thus, document that this divergence exists.

There are proposals for how we can align the ABI rules to eliminate this discrepancy, and I would like to follow through with those, but for now I think we can at least document that the discrepancy exists.

For further discussion please see [Re-evaluate ABI compatibility rules in light of CFI](https://github.com/rust-lang/unsafe-code-guidelines/issues/489) and [Can CFI be made compatible with type erasure schemes?](https://github.com/rust-lang/rust/issues/128728) and [`fn_cast!` macro](https://github.com/rust-lang/rust/issues/140803).

cc @rcvalle @samitolvanen @maurer @bjorn3 @RalfJung

Rendered:

<img width="956" height="391" alt="image" src="https://github.com/user-attachments/assets/410d3eaa-9476-4800-9ef8-bbb100a100c5" />
2026-04-28 20:24:32 +02:00
Alice Ryhl aef93ca43a Document that CFI diverges from Rust wrt. ABI-compatibility rules 2026-04-28 15:16:49 +00:00
mejrs 0eda44baac Delete the 12 year old fixme 2026-04-28 12:00:48 +02:00
Chris Denton 69cc5fa4b0 Remove unnecessary get_unchecked
My benchmarking did not show any issue with using the safe method instead so I assume this isn't an issue any more. But let's do a perf run to be sure.
2026-04-27 03:28:16 +00:00
Jacob Pratt 7695b849d4 Rollup merge of #155588 - BennoLossin:frt-traits, r=Mark-Simulacrum
Implement more traits for FRTs

From https://github.com/rust-lang/rust/pull/154927#discussion_r3068460955.

FRTs now implement the following traits: `Sized + Freeze + RefUnwindSafe + Send + Sync + Unpin + UnsafeUnpin + UnwindSafe + Copy + Debug + Default + Eq + Hash + Ord`.

Let me know if there is any trait missing.

I also removed the explicit  `Send` and `Sync` impls, since commit cb37ee2c87 ("make field representing types invariant over the base type") made the auto-trait impl work even if `T: !Send` or `T: !Sync`. Very happy to see unsafe impls get dropped :)

Note that I used the reflection feature (cc @oli-obk) to print the actual field names in the debug implementation. I think this is a cool way to use it, but if it isn't ready for that, I'm happy to change it to the alternative implementation I gave in the note comment (it's essentially Mark's suggestion but printing `T`'s name instead of `Self`'s).

Since this is a library change, I'll give this to Mark; feel free to also take a look/leave comments, Oli :)

r? @Mark-Simulacrum
2026-04-26 21:56:41 -04:00
Zac Harrold 2aeb041aba Revert documentation changes from 08bd077
These changes were made falsely assuming documentation links from `core` to `std` were not possible. Since it is possible, we can restore the documentation to its original form prior to the `core::io` move.
2026-04-27 09:31:08 +10:00
Jonathan Brouwer 9170ff7733 Rollup merge of #155574 - bushrat011899:core_io_raw_os_error, r=Mark-Simulacrum
Move `std::io::RawOsError` to `core::io`

ACP: https://github.com/rust-lang/libs-team/issues/755
Tracking issue: https://github.com/rust-lang/rust/issues/154046
Related: https://github.com/rust-lang/rust/pull/154654

## Description

As a part of moving components of `std::io` into `alloc::io` and `core::io`, there will need to be a new home for the type `RawOsError`. In this PR, I propose moving it to `core::io`, and removing it from `std::sys`. I suspect this will be quite controversial as it is a platform dependent type, but this is not the only instance of a type being conditioned on `target_os` in `core` (e.g., `core::os` and `core::ffi`).

Since `RawOsError` is currently unstable, I think it's reasonable to make this move now, and worry about making it platform independent if/when it is stabilized (e.g., replacing it with a wrapper around `isize` on all platforms).

---

## Notes

* No AI tooling of any kind was used during the creation of this PR.
2026-04-26 19:06:25 +02:00
Jonathan Brouwer 691ab1b396 Rollup merge of #153457 - dianne:no-coercing-in-pin-macro, r=Mark-Simulacrum,jackh726
prevent deref coercions in `pin!`

Mitigates rust-lang/rust#153438 using a (hopefully temporary!) typed macro idiom to ensure that when `pin!` produces a `Pin<&mut T>`, its argument is of type `T`. See https://github.com/rust-lang/rust/issues/153438#issuecomment-4006727101 for my ideas on how this could be changed in the future.
2026-04-26 19:06:24 +02:00
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
Jacob Pratt b3ccc964d5 Rollup merge of #154372 - Apersoma:float_masks, r=tgross35
Exposing Float Masks

Tracking issue: rust-lang/rust#154064
ACP: rust-lang/libs-team#753
2026-04-25 01:21:52 -04:00
Apersoma d5b941d163 added float masks feature 2026-04-24 23:06:04 +00:00
Jonathan Brouwer 6d6b99eab2 Rollup merge of #155754 - folkertdev:hide-core-ffi-va-list, r=tgross35
make the `core::ffi::va_list` module private

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

the types are exported from `core::ffi` itself.

T-libs-api decided that we should only export the types from `core::ffi`, and should not make `core::ffi::va_list` public, see https://github.com/rust-lang/rust/issues/44930#issuecomment-4289951633.

r? tgross35
2026-04-25 00:08:09 +02:00
Folkert de Vries 3851c60cf8 make the core::ffi::va_list module private
the types are exported from `core::ffi` itself
2026-04-24 22:18:22 +02:00
Muhtasim-Rasheed 52b93e04f8 Fix typo by removing extra 'to' 2026-04-24 18:18:08 +06: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
dianne 5276fcd28e prevent deref coercions in pin! 2026-04-23 19:55:51 -07:00
Jonathan Brouwer d289cc7f53 Rollup merge of #155614 - folkertdev:rename-next-arg, r=tgross35
c-variadic: rename `VaList::arg` to `VaList::next_arg`

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

per [the T-libs-api meeting](https://hackmd.io/d9D6vUnuTnCWygkc3hffEw#nominated-rusttf44930-Tracking-issue-for-RFC-2137-Support-defining-C-compatible-variadic-functions-in-Rust-c_variadic), rename `VaList::arg` to `VaList::next_arg`.
2026-04-23 09:38:23 +02:00
Jonathan Brouwer 04bcb393ab Rollup merge of #155265 - Apersoma:isqrt-smarter, r=jhpratt,tgross35
Improved assumptions relating to isqrt

Improved various assumptions relating to values yielded by `isqrt`.
Does not solve but does improve rust-lang/rust#132763.

Re-openeing of rust-lang/rust#154115

Added assumptions are:
* if `x` is nonzero then `x.isqrt()`  is nonzero
* `x.isqrt() <= x`
* `x.isqrt() * x.isqrt() <= x`
2026-04-23 09:38:21 +02:00
Apersoma e722ba58ed improved assumptions relating isqrt (squashed) 2026-04-22 21:58:59 +00:00
Jonathan Brouwer d7bb378724 Rollup merge of #155133 - cuviper:duration_fp_docs, r=the8472
Document precision considerations of `Duration`-float methods

A `Duration` is essentially a 94-bit value (64-bit sec and ~30-bit ns),
so there's some inherent loss when converting to floating-point for
`mul_f64` and `div_f64`. We could go to greater lengths to compute these
with more accuracy, like rust-lang/rust#150933 or rust-lang/rust#154107,
but it's not clear that it's worth the effort. The least we can do is
document that some rounding is to be expected, which this commit does
with simple examples that only multiply or divide by `1.0`.

This also changes the `f32` methods to just forward to `f64`, so we keep
more of that duration precision, as the range is otherwise much more
limited there.
2026-04-22 19:18:27 +02:00
Folkert de Vries 84cd23b3c8 c-variadic: rename VaList::arg to VaList::next_arg 2026-04-22 16:02:11 +02:00
yukang 8d75f0cbfc add on_unmatch_args 2026-04-22 19:28:44 +08:00
Folkert de Vries 6ca836bc5b c-variadic: tweak std docs 2026-04-21 22:44:26 +02:00
Benno Lossin 104914e614 field representing types: implement Hash, Eq & Ord 2026-04-21 09:28:53 +02:00
Benno Lossin f3719b1686 field representing types: implement Default 2026-04-21 09:27:55 +02:00
Benno Lossin 59f18c21b0 field representing types: implement Debug through reflection
Using the reflection experiment, we can print the actual names of the
field that an FRT is referring to. In case this breaks, there is an
alternative implementation in the note comment.
2026-04-21 09:22:28 +02:00
Benno Lossin 2c79213bc5 field representing types: remove explicit Send and Sync impls
Commit cb37ee2c87 ("make field representing types invariant over the
base type") made the auto-trait impl work even if `T: !Send` or `T:
!Sync` thus we can remove these explicit unsafe impls while FRTs still
implement `Send` and `Sync`.
2026-04-21 09:20:02 +02:00