8472 Commits

Author SHA1 Message Date
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
Yukang
6fd1c2bd94 add doc alias for set_times
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2025-10-08 20:38:56 -07:00
Yukang
1dd5641d74 add doc alias for set_times_nofollow
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2025-10-08 20:38:56 -07:00
yukang
2438df75fe support fs::set_times for wasi 2025-10-08 20:38:56 -07:00
yukang
46c6f0aade rebase #147504 2025-10-08 20:38:56 -07:00
yukang
1c5c8caad2 use proper unsupported 2025-10-08 20:38:52 -07:00
Yukang
6308e76cd7 Update library/std/src/fs.rs
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2025-10-09 10:33:35 +08:00
Yukang
3d40fa6958 Update library/std/src/fs.rs
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2025-10-09 10:33:35 +08:00
yukang
722545427f Implement fs api set_times and set_times_nofollow 2025-10-09 10:33:29 +08:00
Evan Jones
0e2130c2c9
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. Make the docs for the two
nearly the same.
2025-10-08 16:02:31 -04:00
U. Lasiotus
a828ffcf5f Add Motor OS std library port
Motor OS was added as a no-std Tier-3 target in
https://github.com/rust-lang/rust/pull/146848
as x86_64-unknown-motor.

This patch/PR adds the std library for Motor OS.

While the patch may seem large, all it does is proxy
std pal calls to moto-rt. When there is some non-trivial
code (e.g. thread::spawn), it is quite similar, and often
identical, to what other platforms do.
2025-10-08 08:57:58 -07:00
Josh Triplett
1bf555c947 library: fs: Factor out the Apple file time to attrlist code for reuse 2025-10-07 13:18:38 -07:00
Josh Triplett
1e6b444df7 library: fs: Factor out a file_time_to_timespec function in preparation for reusing it 2025-10-07 13:16:54 -07:00
Matthias Krüger
60bbb533df
Rollup merge of #147205 - alexcrichton:wasip3, r=davidtwco
Add a new `wasm32-wasip3` target to Rust

This commit adds a new tier 3 target to rustc, `wasm32-wasip3`. This follows in the footsteps of the previous `wasm32-wasip2` target and is used to represent binding to the WASIp3 set of APIs managed by the WASI subgroup to the WebAssembly Community Group.

As of now the WASIp3 set of APIs are not finalized nor standardized. They're in the process of doing so and the current trajectory is to have the APIs published in December of this year. The goal here is to get the wheels turning in Rust to have the target in a
more-ready-than-nonexistent state by the time this happens in December.

For now the `wasm32-wasip3` target looks exactly the same as `wasm32-wasip2` except that `target_env = "p3"` is specified. This indicates to crates in the ecosystem that WASIp3 APIs should be used, such as the [`wasip3` crate]. Over time this target will evolve as implementation in guest toolchains progress, notably:

* The standard library will use WASIp3 APIs natively once they're finalized in the WASI subgroup.
* Support through `wasi-libc` will be updated to use WASIp3 natively which Rust will then transitively use.
* Longer-term, features such as cooperative multithreading will be added to the WASIp3-track of targets to enable using `std::thread`, for example, on this target.

These changes are all expected to be non-breaking changes for users of this target. Runtimes supporting WASIp3, currently Wasmtime and Jco, support WASIp2 APIs as well and will work with components whether or not they import WASIp2, both WASIp2 and WASIp3, or just WASIp3 APIs. This means that changing the internal implementation details of libstd over time is expected to be a non-breaking change.

[`wasip3` crate]: https://crates.io/crates/wasip3
2025-10-07 19:39:07 +02:00
cyrgani
0bc6945186
give a better example why std modules named like primitives are needed 2025-10-05 13:58:11 +02:00
Stuart Cook
56c96aebfc
Rollup merge of #147328 - EFanZh:lock-with, r=joboet
Implement non-poisoning `Mutex::with_mut`, `RwLock::with` and `RwLock::with_mut`

ACP: https://github.com/rust-lang/libs-team/issues/497.
2025-10-05 15:35:04 +11:00
Matthias Krüger
c389e2ed9e
Rollup merge of #147190 - joboet:sys-net-cleanup, r=hkBst,tgross35
std: `sys::net` cleanups

This PR contains three improvements to the socket-based networking implementation (aa1263e7684341a73b600eaf0bbc70067e196243 is just to add the now missing `unsafe`). Best reviewed commit-by-commit.
2025-10-04 17:11:11 +02:00
Matthias Krüger
baea20ba44
Rollup merge of #146451 - DimitriiTrater:atan2_correctness_docs, r=tgross35
Fix atan2 inaccuracy in documentation

Fixes rust-lang/rust#136275
2025-10-04 17:11:09 +02:00
EFanZh
ba42380142 Implement non-poisoning Mutex::with_mut, RwLock::with and RwLock::with_mut
ACP: https://github.com/rust-lang/libs-team/issues/497.
2025-10-04 17:16:00 +08:00
Fletcher Porter
1485e7887b Document fully-qualified syntax in as' keyword doc 2025-10-03 17:31:55 +03:00