28293 Commits

Author SHA1 Message Date
Zac Harrold 08bd077df4 Make documentation for std::io::ErrorKind core::io compatible
Certain links will not be valid when moved into `core::io`
2026-04-20 08:29:15 +10: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 7b658037fd Rollup merge of #154865 - sunshowers:binary-search-test, r=Mark-Simulacrum
libtest: use binary search for --exact test filtering

When `--exact` is passed in, use binary search for O(f log n) lookups instead of an O(n) linear scan, under the assumption that f << n (which is true for the most relevant cases).

This is important for Miri, where the interpreted execution makes the linear scan very expensive.

I measured this against a repo with 1000 empty tests, running `cargo +stage1 miri nextest run test_00` (100 tests) under hyperfine:

* Before (linear scan): 49.7s ± 0.6s
* After (binary search): 41.9s ± 0.2s  (-15.7%)

I also tried a few other variations (particularly swapping matching tests to the front of the list + truncating the list), but the index + swap_remove approach proved to be the fastest.

Questions:

- [ ] To be conservative, I've assumed that test_main can potentially receive an unsorted list of tests. Is this assumption correct?
2026-04-19 16:04:32 +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
Trevor Gross 996b57d5bc test: Fix printing bitwise float reprs in error printing
In commit "test: Consolidate `Hexf`, `Hexi`, and the `Hex` trait" we
unintentionally lost the difference between float hex and bitwise hex
formatting; instead, the float hex was getting printed twice. Resolve
this by printing the integer hex whenever the `-` format modifier is
specified.  This also makes things simpler because we no longer need to
keep track of whether an `impl DisplayHex` is a float with `.to_bits()`
available or an integer without it, we can always just try to print both
forms.

As a result, we can use a common error message for all validation
checks.
2026-04-18 23:51:56 -04:00
Daniel Scherzer 0cc3a7d6fe c-b: add missing word in src/mem/impls.rs docs 2026-04-18 21:42:33 -04:00
bors 6f109d8a2d Auto merge of #155223 - teor2345:fndef-refactor, r=mati865
Refactor FnDecl and FnSig non-type fields into a new wrapper type





#### Why this Refactor?

This PR is part of an initial cleanup for the [arg splat experiment](https://github.com/rust-lang/rust/issues/153629), but it's a useful refactor by itself.

It refactors the non-type fields of `FnDecl`, `FnSig`, and `FnHeader` into a new packed wrapper types, based on this comment in the `splat` experiment PR:
https://github.com/rust-lang/rust/pull/153697#discussion_r3004637413

It also refactors some common `FnSig` creation settings into their own methods. I did this instead of creating a struct with defaults.

#### Relationship to `splat` Experiment

I don't think we can use functional struct updates (`..default()`) to create `FnDecl` and `FnSig`, because we need the bit-packing for the `splat` experiment.

Bit-packing will avoid breaking "type is small" assertions for commonly used types when `splat` is added.
This PR packs these types:
- ExternAbi: enum + `unwind` variants (38) -> 6 bits
- ImplicitSelfKind: enum variants (5) -> 3 bits
- lifetime_elision_allowed, safety, c_variadic: bool -> 1 bit

#### Minor Changes

Fixes some typos, and applies rustfmt to clippy files that got skipped somehow.
2026-04-18 23:46:37 +00:00
Jonathan Brouwer 22aef0f0ae Rollup merge of #155406 - alexcrichton:update-wasi-deps, r=Mark-Simulacrum
std: Update dependency on `wasi` crate

This commit updates the crate dependency that the standard library has on the `wasi` crate. This is now updated to depending explicitly on the `wasip1` crate and the `wasip2` crate published on crates.io. These crates are managed in the [same location][repo] as the `wasi` crate and represent a different versioning scheme which doesn't require multi-version WASI support to require depending on the same crate at multiple versions. The code in libstd is updated to reference `wasip1` and `wasip2` directly as well.

[repo]: https://github.com/bytecodealliance/wasi-rs
2026-04-18 19:23:16 +02:00
Jonathan Brouwer f0df37fac1 Rollup merge of #155255 - Zoxc:ub-issue-16, r=Mark-Simulacrum
Document why `layout.align() + layout.size()` doesn't overflow

This addition looks suspicious and is safety critical, but is saved by the weird `Layout` invariants.
2026-04-18 19:23:15 +02:00
Jonathan Brouwer 74fd4a720f Rollup merge of #155187 - ArshLabs:fix/hashmap-rng-doc-wording, r=Mark-Simulacrum
std: fix HashMap RNG docs wording

Fixes a wording typo in the top-level HashMap docs.

Changed "random number coroutine" to "random number generator" in the seed entropy paragraph.

This section is security-relevant, and "generator" is the correct term in RNG context.

Testing:
- Not run locally (docs-only text change).
2026-04-18 19:23:14 +02:00
Jonathan Brouwer f7668674cc Rollup merge of #154003 - ginnyTheCat:uefi-file-send, r=Mark-Simulacrum
Make std::fs::File Send on UEFI

Similarly to rust-lang/rust#150990 since UEFI has no threads, this should be safe.
2026-04-18 19:23:14 +02:00
Jonathan Brouwer 92a2343356 Rollup merge of #146870 - DiuDiu777:box-doc-fix, r=Mark-Simulacrum
fix: add aliasing rules for Box

This is a new revised version for the PR [139857](https://github.com/rust-lang/rust/pull/139857), sorry for the delayed reply. I've rewritten the sentence to closely mirror the wording from `Vec::from_raw_parts`, which clearly states the transfer of ownership and its consequences. This should make the aliasing requirements much clearer.

I opted not to include a note about `mem::forget` by default to keep the documentation focused on the primary contract, similar to `Vec`.
2026-04-18 19:23:13 +02:00
Jonathan Brouwer e28fb66f82 Rollup merge of #155284 - RalfJung:net-nonblocking, r=Mark-Simulacrum
net::tcp/udp: fix docs about how set_nonblocking is implemented

`fcntl` `FIONBIO` doesn't even make sense, it should be `fcntl` `F_SETFL`. However, for some reason we are using `ioctl` by default -- except on Solaris where this doesn't seem to work very well.

Honestly what I would have expected is that we just always use `FileDesc::set_nonblocking` also for network sockets, but for some reason we don't and there are no comments explaining this choice. Cc @nikarh (for "vita") @joboet
2026-04-18 19:23:12 +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
Lukas Bergdoll 3a0c0e9cb7 Apply review feedback 2026-04-18 15:12:33 +02: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 4fa293c965 Rollup merge of #155454 - MadeInShineA:issue-155275-fix, r=lqd
docs: Fix typo in std/src/thready/scoped.rs

# Fix typo in std/src/thread/scoped.rs

## Why this pr

This PR fixes the typo mentioned in rust-lang/rust#155275.

I know this was originally fixed in rust-lang/rust#155325 and then in rust-lang/rust#155328.

But since the first issue was closed due to some ai slop and the second one was closed because the first one was already opened, it seems to me that this PR is still needed.

## What this pr does

This PR "just" fixes a typo inside the `std/src/thread/scoped.rs` file

Changing the comment from this:

```
/// borrow non-`'static` data from the outside the scope. See [`scope`] for
/// details.
```

to this:

```
/// borrow non-`'static` data from outside the scope. See [`scope`] for
/// details.
```
2026-04-18 00:05:21 -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
Olivier Amacker 10cc6c4a39 docs: Fix typo in std/src/thread/scoped.rs 2026-04-17 19:39:18 +02:00
aisr d9c717783e remove unnecessary safety conditions related to unchecked uint arithmetic 2026-04-17 23:44:35 +08:00
Jonathan Brouwer f67a3759bf Rollup merge of #155049 - quixoticaxis:weak-upgrade-documentation-extension, r=jhpratt
Documenting the case of `Weak::upgrade` returning `None` when the value behind the reference is missing

Adds a clause to the documentation of `Weak` for `Arc` which was discussed in rust-lang/rust#154936.

Adds the same clause to the documentation of `Weak` for `Rc`, because the behavior is the same.
2026-04-17 13:28:59 +02:00
Jonathan Brouwer 932d807e7e Rollup merge of #153178 - sorairolake:feature/try-from-int-error-kind, r=tgross35
Add `TryFromIntError::kind` method and `IntErrorKind::NotAPowerOfTwo` variant

- ACP: rust-lang/libs-team#746
- Tracking issue: rust-lang/rust#153978

This pull request adds `kind` method to [`TryFromIntError`](https://doc.rust-lang.org/core/num/struct.TryFromIntError.html), which outputs the detailed cause of converting an integer failing.

This is primarily intended for use in cases where there are multiple causes for failure, such as converting from a large signed integer type to a small signed integer type.

At the moment, this method returns [`&IntErrorKind`](https://doc.rust-lang.org/core/num/enum.IntErrorKind.html). This type implements the `Copy` trait and could return `IntErrorKind`, but returns a reference to align with the behavior of [`ParseIntError::kind`](https://doc.rust-lang.org/core/num/struct.ParseIntError.html#method.kind). If it is not necessary to align the behavior of `TryFromIntError::kind` with `ParseIntError::kind`, I'll change this method to return `IntErrorKind`.

Before this pull request, `IntErrorKind` was only used by [`ParseIntError`](https://doc.rust-lang.org/core/num/struct.ParseIntError.html), but I changed it to be used by `TryFromIntError` as well, so I updated `IntErrorKind`'s documentation.

[`impl TryFrom<usize> for Alignment`](https://doc.rust-lang.org/std/ptr/struct.Alignment.html#impl-TryFrom%3Cusize%3E-for-Alignment) returns `TryFromIntError` as an error if the given value is not a power of two. However, `IntErrorKind` does not have a variant that represents this. So I added the variant `NotAPowerOfTwo` to represent this. For this variant to stabilize, both `try_from_int_error_kind` and `ptr_alignment_type` features must be stabilized.
2026-04-17 13:28:58 +02:00
Jonathan Brouwer ea736ba569 Rollup merge of #149614 - WaffleLapkin:dangle-maybe, r=jhpratt
Use `MaybeDangling` in `std`

cc https://github.com/rust-lang/rust/issues/118166
2026-04-17 13:28:57 +02:00
Lukas Bergdoll e0ef87f880 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-17 13:04:29 +02:00
Tshepang Mbambo 9b36d40819 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-17 12:03:58 +02:00
Sergey Ivanov f580872fe2 Extended the documentation for Arc's Weak::upgrade 2026-04-17 07:47:34 +00: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 9de2e2bfd7 Rollup merge of #155413 - StepfenShawn:patch-2, r=ChrisDenton
fix: typo in `std::fs::hard_link` documentation

Change "corresponds the" to "corresponds to the" in the documentation for `std::fs::hard_link`.
2026-04-17 16:18:02 +10:00
Stuart Cook fd57bed92e Rollup merge of #155396 - oconnor663:link_typo, r=folkertdev
`as_ref_unchecked` docs link fix

Fix what's probably a copy-paste-o in a docs link.
2026-04-17 16:18:01 +10:00
Stuart Cook 16b22a7e0f Rollup merge of #155305 - Zoxc:ub-issue-2, r=tgross35
Make `convert_while_ascii` unsafe

`convert_while_ascii` assumes `convert` only returns ASCII to ensure the output remains valid UTF-8. This adds that requirement as a safety precondition.
2026-04-17 16:17:55 +10:00
Stuart Cook 6951f83914 Rollup merge of #155335 - Mark-Simulacrum:bootstrap-bump, r=jieyouxu
Bump bootstrap to 1.96 beta

See https://forge.rust-lang.org/release/process.html#default-branch-bootstrap-update-tuesday

I think this will wind up needing another PR in a week or so when we pick up assert_matches getting destabilized in beta? But that seems like it can be split into its own PR.
2026-04-17 16:17:52 +10:00
Stuart Cook b7ea9df119 Rollup merge of #155318 - Zoxc:ub-issue-50, r=ChrisDenton
Use mutable pointers for Unix path buffers

This gets mutable pointers for Unix path buffers to ensure they have the right provenance.
2026-04-17 16:17:51 +10:00
Stuart Cook 3c61fba50b Rollup merge of #154491 - Jules-Bertholet:case-docs, r=Mark-Simulacrum,GuillaumeGomez
Extend `core::char`'s documentation of casing issues (and fix a rustdoc bug)

@rustbot label A-unicode A-docs
2026-04-17 16:17:50 +10: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
Shun Sakai c35ed1ac32 feat: Add TryFromIntError::kind and IntErrorKind::NotAPowerOfTwo 2026-04-17 14:04:56 +09:00
bors 1b8f2e46e1 Auto merge of #155207 - quiode:writable, r=RalfJung
add llvm writable attribute conditionally




This PR tries to address https://github.com/rust-lang/unsafe-code-guidelines/issues/584#issue-3440604811. It is part of a bachelor thesis supervised by @JoJoDeveloping and @RalfJung, for more information, see: [Project_Description.pdf](https://github.com/user-attachments/files/26537277/Project_Description.pdf).
If the new `-Zllvm-writable` flag is set, the [llvm writable attribute](https://llvm.org/docs/LangRef.html#writable) is inserted for all mutable borrows. This can be conditionally turned off on a per-function basis using the `#[rustc_no_writable]` attribute. The new Undefined Behaviour introduced by this can detected by Miri, which is implemented here: https://github.com/rust-lang/miri/pull/4947.

Two library functions already received the `#[rustc_no_writable]` attribute, as they are known to cause problems under the Tree Borrows aliasing model with implicit writes enabled.
2026-04-17 04:13:36 +00:00
🍌Shawn b05e29b8cb Fix typo in documentation for CreateHardLink function 2026-04-17 11:52:59 +08:00
Josh Stone a66b7810c3 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
2026-04-16 16:49:11 -07:00
John Kåre Alsaker 7a47964d3f Use mutable pointers for Unix path buffers 2026-04-17 01:08:08 +02:00
Trevor Gross 5d4b1764c1 bench: Use a group with many benches rather than many groups 2026-04-16 18:18:54 -04:00
bors 0204aca066 Auto merge of #155385 - davidtwco:stdarch-sync-160426, r=davidtwco
stdarch subtree update

Subtree update of `stdarch` to https://github.com/rust-lang/stdarch/commit/095646219d35769f013c4a54d843a982c87d979c.

Created using https://github.com/rust-lang/josh-sync.

r? @ghost
2026-04-16 21:38:27 +00:00