10557 Commits

Author SHA1 Message Date
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
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
Jacob Pratt 53b9b9a108 Rollup merge of #155564 - tshakalekholoane:tshaka/const_default/cstr, r=jhpratt
Implement const Default for &CStr

Implements `const Default` for `&CStr`.

Tracking issue: rust-lang/rust#143894.
2026-04-21 02:20:27 -04:00
Jacob Pratt 64b897180d Rollup merge of #155559 - safer-rust:fix-doc2, r=jhpratt
add safety doc (section header) to two unsafe methods in `NonZero`

This PR adds a Safety section to two unsafe methods in `NonZero`:
- [unchecked_add](https://doc.rust-lang.org/nightly/core/num/struct.NonZero.html#method.unchecked_add)
- [unchecked_mul](https://doc.rust-lang.org/nightly/core/num/struct.NonZero.html#method.unchecked_mul)

The safety documentation is now consistent with that of [`u8::unchecked_add`](https://doc.rust-lang.org/nightly/core/primitive.u8.html#method.unchecked_add) and [`u8::unchecked_mul`](https://doc.rust-lang.org/nightly/core/primitive.u8.html#method.unchecked_mul).
2026-04-21 02:20:26 -04:00
Jacob Pratt 156cc9fb23 Rollup merge of #155558 - nivekithan:issue-154000-fix, r=jhpratt
Clarify that isqrt returns the principal (non-negative) square root

Clarify which root is returned from `isqrt` and `checked_isqrt`

Fixes: https://github.com/rust-lang/rust/issues/154000
Previous PRs: https://github.com/rust-lang/rust/pull/154462
2026-04-21 02:20:26 -04:00
Zac Harrold 7653e5ea01 Move RawOsError to core::io 2026-04-21 09:04:58 +10:00
bors c28e303778 Auto merge of #155552 - JonathanBrouwer:rollup-JKIpTuW, r=JonathanBrouwer
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#154654 (Move `std::io::ErrorKind` to `core::io`)
 - rust-lang/rust#145270 (Fix an ICE observed with an explicit tail-call in a default trait method)
 - rust-lang/rust#154895 (borrowck: Apply `user_arg_index` nomenclature more broadly)
 - rust-lang/rust#155213 (resolve: Make sure visibilities of import declarations make sense)
 - rust-lang/rust#155346 (`single_use_lifetimes`: respect `anonymous_lifetime_in_impl_trait`)
 - rust-lang/rust#155517 (Add a test for Mach-O `#[link_section]` API inherited from LLVM)
 - rust-lang/rust#155549 (Remove some unnecessary lifetimes.)
 - rust-lang/rust#154248 (resolve :  mark repr_simd as internal)
 - rust-lang/rust#154772 (slightly optimize the `non-camel-case-types` lint)
 - rust-lang/rust#155541 (Add `#[rust_analyzer::prefer_underscore_import]` to the traits in `rustc_type_ir::inherent`)
 - rust-lang/rust#155544 (bootstrap: Make "detected modifications" for download-rustc less verbose)
2026-04-20 16:15:13 +00:00
Tshaka Lekholoane 339a2f0ba0 Implement const Default for &CStr 2026-04-20 17:40:30 +02:00
aisr 0bfdb18855 add safety sections to two unsafe methods in NonZero 2026-04-20 22:46:10 +08:00
Nivekithan 6b8cb42ee3 update doc to be more clear 2026-04-20 18:55:05 +05:30
Zac Harrold fe2b39f064 Move std::io::ErrorKind to core::io
Move `std::io::ErrorKind` to `core::io`
* Update `rustdoc-html` tests for the new path
* Add `core_io` feature to control stability. This replaces the use of `core_io_borrowed_buf` on the `core::io` module itself.
* Re-export `core::io::ErrorKind` in `std::io::error`
2026-04-20 18:38:25 +10:00
Jonathan Brouwer 2e5a9fc307 Rollup merge of #155531 - Jules-Bertholet:is_ascii_punctuation_docs, r=scottmcm
Tweak `is_ascii_punctuation()` docs wording

These methods return `true` for characters with Unicode general category of punctuation (P), but also for those with general category of symbol (S).

@rustbot label A-docs
2026-04-20 08:14:14 +02:00
Jonathan Brouwer ede69dad7d Rollup merge of #155493 - sorairolake:fix-alignment-doc-link, r=scottmcm
docs(num): fix stale link to `mem::Alignment`

This pull request updates a stale link to `mem::Alignment` in `num::IntErrorKind`.

In rust-lang/rust#153178, I added a link to `Alignment` in `IntErrorKind`, but I overlooked that `Alignment` had been moved from `core::ptr` to `core::mem`. Although it is still re-exported in `core::ptr`, this pull request points the link to its canonical location.

@rustbot label +A-docs
2026-04-20 08:14:13 +02:00
Jonathan Brouwer 26f47ae831 Rollup merge of #154664 - okaneco:integer_cast_extras, r=scottmcm
core/num: Implement feature `integer_cast_extras`

Tracking issue https://github.com/rust-lang/rust/issues/154650
Accepted ACP https://github.com/rust-lang/libs-team/issues/765#issuecomment-4164285847

Implement `saturating`, `checked`, and `strict` casting between signed and unsigned integer primitives of the same bit-width.

Add `cast_integer` panic function to `overflow_panic.rs`
2026-04-20 08:14:11 +02:00
Jules Bertholet fd65209a77 Tweak is_ascii_punctuation()/graphic() docs wording
The `_punctuation` methods return `true` for characters with
Unicode general category of punctuation (P),
but also for those with general category
of symbol (S).
2026-04-19 22:27:16 -04:00
Jonathan Brouwer e7c135e282 Rollup merge of #154979 - ArtemIsmagilov:must-use-floats, r=jhpratt
add #[must_use] macros for floats

try resolve rust-lang/rust#154854
2026-04-19 16:04:33 +02:00
Jonathan Brouwer b07688dc2e Rollup merge of #153873 - folkertdev:deprecate-char-max, r=Mark-Simulacrum
deprecate `std::char` constants and functions

similar to how constants in those modules for numeric types have been deprecated. The `std::char` module contains:

Three stable constants that this PR deprecates. These already link to their associated constant equivalents.

- `MAX`
- `REPLACEMENT_CHARACTER`
- `UNICODE_VERSION`

two unstable constants that this PR removes. The constants are already stablized as associated constants on `char`.

- `MAX_LEN_UTF8`
- `MAX_LEN_UTF16`

Four stable functions that this PR deprecates. These already link to their method equivalents.

- `fn decode_utf16`
- `fn from_digit`
- `fn from_u32`
- `fn from_u32_unchecked⚠`

discussion at [#t-libs > should &#96;std::char::{MIN, MAX}&#96; be deprecated?](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/should.20.60std.3A.3Achar.3A.3A.7BMIN.2C.20MAX.7D.60.20be.20deprecated.3F/with/579444750).

r? libs-api
2026-04-19 16:04:32 +02:00
Jonathan Brouwer ffcda118ca Rollup merge of #155431 - Voultapher:add-tmp-scope-to-assert-matches, r=Amanieu
Add temporary scope to assert_matches

Addresses https://github.com/rust-lang/rust/issues/154406 in part. `assert_eq` will be done in a separate PR.
2026-04-19 16:04:31 +02:00
Jonathan Brouwer 77cbf96954 Rollup merge of #150230 - bend-n:trusted_len_spec_for_iter_next_chunk, r=Mark-Simulacrum
spec next chunk for trustedlen

relevant to rust-lang/rust#98326
2026-04-18 19:23:12 +02:00
Shun Sakai 8eb89a8b06 docs(num): fix stale link to mem::Alignment 2026-04-19 02:07:18 +09:00
Artem Ismagilov 607021cb1d add must_use macros
add msg
2026-04-18 11:23:14 +04:00
Jacob Pratt 0bfd952a27 Rollup merge of #155467 - DanielEScherzer:patch-2, r=mejrs
`std::error::Request`: clean up documentation
2026-04-18 00:05:22 -04:00
Jacob Pratt 0c326ece10 Rollup merge of #155450 - safer-rust:fix-doc2, r=jhpratt
Remove unnecessary safety conditions related to unchecked uint arithmetic

Improve the safety documentation of three unsafe APIs related to unsigned integer arithmetic.

- [unchecked_add](https://doc.rust-lang.org/nightly/core/primitive.usize.html#method.unchecked_add): It is impossible for `self + rhs < usize::MIN`.
- [unchecked_sub](https://doc.rust-lang.org/nightly/core/primitive.usize.html#method.unchecked_sub): It is impossible for `self - rhs > usize::MAX`.
- [unchecked_mul](https://doc.rust-lang.org/nightly/core/primitive.usize.html#method.unchecked_mul): It is impossible for `self * rhs < usize::MIN`.

The examples use `usize` for demonstration. All unsigned integer types suffer from the same issue because their APIs are generated by the same macro `uint_impl`, and fixing the macro documentation will fix them all.
2026-04-18 00:05:20 -04:00
Jacob Pratt 8b07a038cb Rollup merge of #155427 - tshepang:tshepang/match-text-in-with_addr, r=scottmcm
ptr: update text in intro text to one in with_addr doc

The one where this was copied from has since been updated.
2026-04-18 00:05:18 -04:00
Jacob Pratt 354bfa49ff Rollup merge of #153511 - DanielEScherzer:patch-3, r=scottmcm
`std::any::TypeId`: remove misplaced "and" in `Unique<T>` example
2026-04-18 00:05:17 -04:00
Jacob Pratt 221dab89b4 Rollup merge of #139690 - cuviper:iter_repeat_n_default, r=tgross35
`impl Default for RepeatN`

This creates an empty iterator, like `repeat_n(value, 0)` but without
needing any such value at hand. There's precedent in many other
iterators that the `Default` is empty, like `slice::Iter`.

I found myself wanting this for rayon's `RepeatN` as it lowers to a
sequential iterator [here][1]. Since rayon is also optimizing to avoid
extra clones, it may end up with parallel splits that have count 0 and
no item value. Calling `std::iter::repeat_n(x, 0)` just drops that
value, but there's no way to construct the same result without a value
yet. This would be straightforward with an empty `Default`.

[1]: https://github.com/rayon-rs/rayon/blob/ae07384e3e0b238cea89f0c14891f351c65a5cee/src/iter/repeat.rs#L201-L202

r? libs-api (insta-stable)
2026-04-18 00:05:16 -04:00
Jacob Pratt db3d08421c Rollup merge of #154935 - Darksonn:dyn-trait-dyn-compat, r=scottmcm
Add Sized supertrait for CoerceUnsized and DispatchFromDyn

This is part of rust-lang/rust#149094. I did not include `Receiver` because I think it is correct to allow non-sized receivers.
2026-04-18 00:05:15 -04:00
Daniel Scherzer 1d1aa9a7fb std::error::Request: more documentation cleanup 2026-04-17 16:16:01 -07:00
Daniel Scherzer 6525e06475 std::error::Request: add missing period in docs
All but one of the bullet points ended with a period; add the missing period.
2026-04-17 15:54:12 -07:00
aisr d9c717783e remove unnecessary safety conditions related to unchecked uint arithmetic 2026-04-17 23:44:35 +08:00