8441 Commits

Author SHA1 Message Date
Josh Stone
f25ca45fd1 Update CURRENT_RUSTC_VERSION post-bump
(cherry picked from commit 813072186c1c305ea62c7270f1514dfab5166af2)
2025-10-28 13:22:00 -07:00
Mads Marquart
66b992d705 Fix compiling CondVar::wait_timeout on 32-bit Apple platforms 2025-10-24 17:36:05 +02:00
Josh Stone
c01682ebf6 Revert "feat: implement hash_map! macro"
This reverts commit 066023e47c.
2025-10-23 12:37:53 -07:00
Josh Stone
a81ed52f58 Add a regression test for rust-lang/rust#147971 2025-10-23 12:37:53 -07:00
Stuart Cook
e93ec9aab4 Rollup merge of #146629 - joboet:reorganize-weak, r=ibraheemdev
std: reorganize the UNIX-internal `weak` module

This moves the `dlsym`-based and weak-linkage versions of the `weak!` macro into separate files, both of which include a common test file. As a result, both versions will be tested on all the platforms where they are used.

Since the `#[link_name]` arm of the `dlsym` version was unused, I've removed it. I've also removed the unused `raw_syscall!` and non-Linux `syscall!` macros and gated the `#[allow(dead_code, unused_macros)]` to only apply on non-Linux platforms, so compilation will fail if `weak` turns out to be unused on all platforms.

The last change concerns the use of `dlsym!` on FreeBSD: it is only used once, to link against `sysctlbyname`. But that symbol is always available, so there is no need for weak linkage.
2025-10-23 12:06:31 +11:00
Stuart Cook
e4bf8b3fc3 Rollup merge of #115501 - michaelvanstraten:set_inherit_handles, r=ChrisDenton
Add new inherit_handles flag to CommandExt trait

This PR adds a new flag to the [`CommandExt`](https://doc.rust-lang.org/stable/std/os/windows/process/trait.CommandExt.html) trait to set whether to inherit the handles of the calling process ([ref][1]).

This is necessary when, for example, spawning a process with a `pseudoconsole` attached.

r? ``@ChrisDenton``

ACP: https://github.com/rust-lang/libs-team/issues/264
[1]: <https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw>
2025-10-23 12:06:30 +11:00
bors
4d94478977 Auto merge of #147826 - Muscraft:update-typos, r=Noratrieb
Update typos

I saw that `typos` was a few versions out of date and figured it would be a good idea to update it. Upgrading to `1.38.1` adds the [July](https://github.com/crate-ci/typos/issues/1331), [August](https://github.com/crate-ci/typos/issues/1345), and [September](https://github.com/crate-ci/typos/issues/1370) dictionary updates. As part of this change, I also sorted the configuration file.
2025-10-22 13:11:47 +00:00
Matthias Krüger
4a117590b7 Rollup merge of #147933 - thaliaarchi:consistent-osstring, r=tgross35
os_str: Make platform docs more consistent

- Port `Buf::as_slice`/`as_mut_slice` wording from wtf8 to bytes
- Make `Buf::extend_from_slice_unchecked` docs more platform-independent
- wtf8 `Buf` was missing `#[repr(transparent)]`
2025-10-22 07:12:12 +02:00
Thalia Archibald
7e2b76e1b6 motor: Use UTF-8 guarantee for OS strings 2025-10-21 16:36:10 -06:00
Thalia Archibald
206ffcc786 os_str: Create UTF-8 platform encoding 2025-10-21 16:29:14 -06:00
Michael van Straten
24b0c27b9a Add new inherit_handles flag to CommandExt trait
This patch adds a new flag to the [`CommandExt`](1) trait to set whether to
inherit the handles of the calling process (2) on Windows systems.

ACP: https://github.com/rust-lang/libs-team/issues/264

[1]: https://doc.rust-lang.org/stable/std/os/windows/process/trait.CommandExt.html
[2]: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw
2025-10-21 18:53:46 +02:00
Matthias Krüger
e2110d8463 Rollup merge of #147930 - thaliaarchi:motor-set-times, r=joboet
motor: Add new `set_times` stubs

Motor OS `std` support (https://github.com/rust-lang/rust/pull/147000) and `set_times`/`set_times_nofollow` (https://github.com/rust-lang/rust/pull/147468) were merged around the same time, so Motor OS is missing this API and currently fails to build.

cc `@lasiotus`
2025-10-21 17:26:40 +02:00
Thalia Archibald
b39fb327cb motor: Add new set_times stubs 2025-10-20 21:45:14 -06:00
Thalia Archibald
563302ea9a os_str: Make platform docs more consistent
- Port `Buf::as_slice`/`as_mut_slice` wording from wtf8 to bytes
- Make `Buf::extend_from_slice_unchecked` docs more platform-independent
- wtf8 `Buf` was missing `#[repr(transparent)]`
2025-10-20 21:26:05 -06:00
Stuart Cook
79e46694de Rollup merge of #147125 - connortsui20:poison-once-remove, r=tgross35
move `once` module out of `poison`

From https://github.com/rust-lang/rust/issues/134645#issuecomment-3324577500, since `Once` will not have a non-poisoning variant, we remove it from the `poison` module.

Additionally:

1. Renames `once::ExclusiveState` to `OnceExclusiveState` since it was a bit confusing reading just `ExclusiveState` where it is used.
2. Reorders a few module definitions and re-exports in `library/std/src/sync/mod.rs` for clarity.

Also, once this is merged, I think that we can begin the process of stabilizing [`sync_poison_mod`](https://github.com/rust-lang/rust/issues/134646)
2025-10-21 12:20:56 +11:00
bors
c7a635f33c Auto merge of #147910 - joboet:wait_timeout-spurious-test, r=ChrisDenton
handle spurious returns of `wait_timeout` in test

Fixes https://github.com/rust-lang/rust/issues/147885
Closes https://github.com/rust-lang/rust/pull/147871

`wait_timeout` is allowed to spuriously return, hence the `timeout_nanoseconds` must not assume that the wakeup resulted from a `notify_all()`.
2025-10-20 22:04:39 +00:00
Scott Schafer
12f6b9697f chore: Update typos to 1.38.1 2025-10-20 12:20:15 -06:00
joboet
76dfdd4e70 handle spurious returns of wait_timeout in test 2025-10-20 17:53:49 +02:00
David Carlier
4333e72715 std:🧵:available_parallelism() vxworks libc symbol usage. 2025-10-19 05:50:26 +01:00
Matthias Krüger
55a3df8cee Rollup merge of #147494 - evanj:evan.jones/thread-spawn-link, r=joboet
std::thread spawn: Docs: Link to Builder::spawn; Make same.

Replace "use this API instead" with a link to Builder::spawn. Edit the paragraph to make it slightly clearer.

The Scope::spawn method already included a link to `Builder::spawn_scoped`. Make the docs for `Scope::spawn` and `thread::spawn` nearly the same.
2025-10-18 15:09:03 +02:00
Matthias Krüger
fc6502976c Rollup merge of #147468 - chenyukang:yukang-api-set-times, r=joshtriplett
Implement fs api set_times and set_times_nofollow

implementation of rust-lang/rust#147455

r? ````@joshtriplett````
2025-10-18 08:08:38 +02:00
Matthias Krüger
b46db5c6b7 Rollup merge of #140153 - thaliaarchi:encode-wide-debug, r=ChrisDenton
Implement `Debug` for `EncodeWide`

Since `std::os::windows::ffi::EncodeWide` was reexported from `std::sys_common::wtf8::EncodeWide`, which has `#![allow(missing_debug_implementations)]` in the parent module, it did not implement `Debug`. When it was moved to `core`, a placeholder impl was added; fill it in.

This becomes insta-stable.

r? libs-api
2025-10-18 08:08:35 +02:00
Connor Tsui
3a9c521285 move once module out of poison
Since `Once` will not have a non-poisoning variant, we remove it from
the `poison` module.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-17 11:43:39 -04:00
Connor Tsui
7b61403c50 reorganize library/std/src/sync/mod.rs file
Moves things around to make a bit more sense (plus prepare moving `once`
out of `poison`.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-17 11:43:38 -04:00
Connor Tsui
0758e191d5 clean up some documentation
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-17 11:43:15 -04:00
Connor Tsui
a61c8be269 rename once::ExclusiveState to OnceExclusiveState
It is a bit confusing when reading code that uses this type since it is
not immediately obvious that it is specific to `Once`.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-17 10:57:39 -04:00
Matthias Krüger
f337e28bd9 Rollup merge of #147773 - timvisee:docs-empty-is-ascii, r=Noratrieb
`is_ascii` on an empty string or slice returns true

Update the description of the [`is_ascii`](https://doc.rust-lang.org/std/primitive.str.html#method.is_ascii) functions - an empty string or slice also returns `true`.

This follows the pattern of [`all()`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.all). Clippy currently suggests to change `string.chars().all(|c| c.is_ascii())` into `string.is_ascii()`. This suggestion therefore seems fitting.

I've already questioned the behavior for this multiple times. I've always had to check the internals to conclude how it works. That's why I'm opening this PR to add it directly in the documentation.
2025-10-16 19:35:28 +02:00
Matthias Krüger
91f48d8ba7 Rollup merge of #147000 - moturus:motor-os_stdlib_pr, r=tgross35
std: Add Motor OS std library port

Motor OS was added as a no-std Tier-3 target in
[PR 146848](https://github.com/rust-lang/rust/pull/146848) as x86_64-unknown-motor.

This PR adds the std library for Motor OS.

While the PR may seem large, all it does is proxy
std pal calls to [moto-rt](https://crates.io/crates/moto-rt). Where there is some non-trivial
code (e.g. thread::spawn), it is quite similar, often
identical, to what other platforms do.
2025-10-16 19:35:23 +02:00
Evan Jones
c4dc39be05 add link to Builder (code review improvement) 2025-10-16 09:07:57 -04:00
timvisee
7a11c72db0 is_ascii on an empty string or slice returns true 2025-10-16 10:52:51 +02:00
Matthias Krüger
8d6356b8d8 Rollup merge of #143191 - connortsui20:stabilize-rwlock-downgrade, r=tgross35
Stabilize `rwlock_downgrade` library feature

Tracking Issue: https://github.com/rust-lang/rust/issues/128203

Method to be stabilized:

```rust
impl<'a, T: ?Sized> RwLockWriteGuard<'a, T> {
    pub fn downgrade(s: Self) -> RwLockReadGuard<'a, T> {}
}
```

~~I would like to point out that my documentation comment is longer than ideal, but at the same time I don't really know how else to show why `downgrade` is actually necessary (instead of just unlocking and relocking). If anyone has ideas for making this more concise that would be great!~~ I have made the documentation a bit more clear.

Stabilization report: https://github.com/rust-lang/rust/issues/128203#issuecomment-3016682463
2025-10-15 23:41:00 +02:00
yukang
8182085617 Fix compiling error for redox etc 2025-10-15 08:02:32 +08:00
Matthias Krüger
2ab43c2f91 Rollup merge of #147669 - cyrgani:cyrgani-patch-1, r=joboet
fix missing link to `std::char` in `std` docs

Missed this in rust-lang/rust#147373.
2025-10-14 19:47:32 +02:00
Matthias Krüger
f8b65f7bc7 Rollup merge of #147526 - bjorn3:alloc_shim_weak_shape, r=petrochenkov,RalfJung
Move computation of allocator shim contents to cg_ssa

In the future this should make it easier to use weak symbols for the allocator shim on platforms that properly support weak symbols. And it would allow reusing the allocator shim code for handling default implementations of the upcoming externally implementable items feature on platforms that don't properly support weak symbols.

In addition to make this possible, the alloc error handler is now handled in a way such that it is possible to avoid using the allocator shim when liballoc is compiled without `no_global_oom_handling` if you use `#[alloc_error_handler]`. Previously this was only possible if you avoided liballoc entirely or compiled it with `no_global_oom_handling`. You still need to avoid libstd and to define the symbol that indicates that avoiding the allocator shim is unstable.
2025-10-14 19:47:29 +02:00
Matthias Krüger
dcd2dd9bba Rollup merge of #146503 - joboet:macos-condvar-timeout, r=ibraheemdev
std: improve handling of timed condition variable waits on macOS

Fixes rust-lang/rust#37440 (for good).

This fixes two issues with `Condvar::wait_timeout` on macOS:

Apple's implementation of `pthread_cond_timedwait` internally converts the absolute timeout to a relative one, measured in nanoseconds, but fails to consider overflow when doing so. This results in `wait_timeout` returning much earlier than anticipated when passed a duration that is slightly longer than `u64::MAX` nanoseconds (around 584 years). The existing clamping introduced by rust-lang/rust#42604 to address rust-lang/rust#37440 unfortunately used a maximum duration of 1000 years and thus still runs into the bug when run on older macOS versions (or with `PTHREAD_MUTEX_USE_ULOCK` set to a value other than "1"). See https://github.com/rust-lang/rust/issues/37440#issuecomment-3285958326 for context.

Reducing the maximum duration alone however would not be enough to make the implementation completely correct. As macOS does not support `pthread_condattr_setclock`, the deadline passed to `pthread_cond_timedwait` is measured against the wall-time clock. `std` currently calculates the deadline by retrieving the current time and adding the duration to that, only for macOS to convert the deadline back to a relative duration by [retrieving the current time itself](1ebf56b3a7/src/pthread_cond.c (L802-L819)) (this conversion is performed before the aforementioned problematic one). Thus, if the wall-time clock is adjusted between the `std` lookup and the system lookup, the relative duration could have changed, possibly even to a value larger than $2^{64}\ \textrm{ns}$. Luckily however, macOS supports the non-standard, tongue-twisting `pthread_cond_timedwait_relative_np` function which avoids the wall-clock-time roundtrip by taking a relative timeout. Even apart from that, this function is perfectly suited for `std`'s purposes: it is public (albeit badly-documented) API, [available since macOS 10.4](1ebf56b3a7/include/pthread/pthread.h (L555-L559)) (that's way below our minimum of 10.12) and completely resilient against wall-time changes as all timeouts are [measured against the monotonic clock](e3723e1f17/bsd/kern/sys_ulock.c (L741)) inside the kernel.

Thus, this PR switches `Condvar::wait_timeout` to `pthread_cond_timedwait_relative_np`, making sure to clamp the duration to a maximum of $2^{64} - 1 \ \textrm{ns}$. I've added a miri shim as well, so the only thing missing is a definition of `pthread_cond_timedwait_relative_np` inside `libc`.
2025-10-14 19:47:28 +02:00
joboet
e043a0b41e std: reorganize the UNIX-internal weak module 2025-10-14 13:36:14 +02:00
joboet
8a145efc70 std: improve handling of timed condition variable waits on macOS 2025-10-14 11:57:50 +02:00
cyrgani
18d1b69c92 fix missing link to std::char in std docs 2025-10-14 10:23:29 +02:00
Stuart Cook
a594163d6d Rollup merge of #147594 - vexide:vexos-exit-impl, r=joboet
std: implement `pal::os::exit` for VEXos

This PR provides a more "proper" implementation of process exiting in VEXos programs by going through `vexSystemExitRequest` rather than calling `intrinsics::abort`, which exits using an undefined instruction trap. This matches the existing implementation of `rt::abort_internal` and therefore makes `std::process::exit` have the same behavior as returning from main on VEXos targets.
2025-10-14 16:31:00 +11:00
bors
ff6dc928c5 Auto merge of #142390 - cjgillot:mir-liveness, r=davidtwco
Perform unused assignment and unused variables lints on MIR.

Rebase of https://github.com/rust-lang/rust/pull/101500

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

The first commit moves detection of uninhabited types from the current liveness pass to MIR building.

In order to keep the same level of diagnostics, I had to instrument MIR a little more:
- keep for which original local a guard local is created;
- store in the `VarBindingForm` the list of introducer places and whether this was a shorthand pattern.

I am not very proud of the handling of self-assignments. The proposed scheme is in two parts: first detect probable self-assignments, by pattern matching on MIR, and second treat them specially during dataflow analysis. I welcome ideas.

Please review carefully the changes in tests. There are many small changes to behaviour, and I'm not sure all of them are desirable.
2025-10-12 13:00:04 +00:00
Matthias Krüger
f5a6b1bda9 Rollup merge of #147503 - stepancheg:instant-now-mac-doc, r=joboet
Fix documentation of Instant::now on mac

It is `CLOCK_UPTIME_RAW` on Apple.

b6f0945e46/library/std/src/sys/pal/unix/time.rs (L260-L264)
2025-10-12 10:13:17 +02:00
Camille Gillot
49922d5b96 Remove unreachable expression warning from std. 2025-10-11 20:50:21 +00:00
Tropical
04da682613 vexos: implement pal::os::exit 2025-10-11 14:42:26 -05:00
dianqk
b01780801a Rollup merge of #147289 - Jules-Bertholet:thread_local-shadow-mitigate, r=joboet
Mitigate `thread_local!` shadowing issues

Mitigates https://github.com/rust-lang/rust/issues/147006 and https://github.com/rust-lang/rust/issues/99018.

`@rustbot` label T-libs A-macros A-thread-locals A-hygiene
2025-10-11 07:05:56 +08:00
Stepan Koltsov
dff4561f59 Fix documentation of Instant::now on mac 2025-10-10 20:01:03 +01:00
bjorn3
116f4ae171 Support #[alloc_error_handler] without the allocator shim
Currently it is possible to avoid linking the allocator shim when
__rust_no_alloc_shim_is_unstable_v2 is defined when linking rlibs
directly as some build systems need. However this requires liballoc to
be compiled with --cfg no_global_oom_handling, which places huge
restrictions on what functions you can call and makes it impossible to
use libstd. Or alternatively you have to define
__rust_alloc_error_handler and (when using libstd)
__rust_alloc_error_handler_should_panic
using #[rustc_std_internal_symbol]. With this commit you can either use
libstd and define __rust_alloc_error_handler_should_panic or not use
libstd and use #[alloc_error_handler] instead. Both options are still
unstable though.

Eventually the alloc_error_handler may either be removed entirely
(though the PR for that has been stale for years now) or we may start
using weak symbols for it instead. For the latter case this commit is a
prerequisite anyway.
2025-10-10 13:04:53 +00:00
Josh Triplett
d2f590a6d5 unsupported: Use unsupported() for set_times_nofollow 2025-10-09 06:37:09 -07:00
Josh Triplett
f8118d88d7 unsupported: Use unsupported() for set_times 2025-10-09 06:36:51 -07:00
yukang
901366af1e fix c_char error in Android 2025-10-09 16:42:54 +08:00
Stuart Cook
800bc95b87 Rollup merge of #147373 - cyrgani:cyrgani-patch-1, r=ibraheemdev
give a better example why `std` modules named like primitives are needed

A small update to the `std` `lib.rs` introduction to replace mentions of `std::i32` (never needed) with `std::char` (sometimes needed).
Related to rust-lang/rust#146882.
2025-10-09 18:43:20 +11:00