Commit Graph

8284 Commits

Author SHA1 Message Date
Jacob Pratt
08db93806b Rollup merge of #146517 - RalfJung:wait-timeout, r=joboet
fix Condvar::wait_timeout docs

[Context](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Condvar.20wait_timeout.20sleep.20duration.20decremented/with/539279839)
r? `@joboet`
2025-09-13 18:55:19 -04:00
Jacob Pratt
5d56e52409 Rollup merge of #146473 - RalfJung:system-time-deconst, r=workingjubilee
Revert "Constify SystemTime methods"

This reverts https://github.com/rust-lang/rust/pull/144519. The const-hacks introduces bugs, and they make the code harder to maintain. Let's wait until we can constify these functions without changing their implementation.

Fixes https://github.com/rust-lang/rust/issues/146228.
Closes https://github.com/rust-lang/rust/issues/144517 (since the feature is gone).
r? `@tgross35`
Cc `@clarfonthey`
2025-09-13 18:55:18 -04:00
Ralf Jung
f21d3fbce9 fix Condvar::wait_timeout docs 2025-09-13 20:13:37 +02:00
Waffle Lapkin
f13c8c2192 fixup become kw documentation wrt #[track_caller] 2025-09-13 19:48:10 +02:00
Maybe Waffle
cc9225406c Document become keyword 2025-09-13 19:48:07 +02:00
Ralf Jung
2baa39e89f also apply revert to wasip2 2025-09-13 10:41:59 +02:00
Ralf Jung
5d8e41b656 Revert "Constify SystemTime methods"
This reverts commit 7ce620dd7c.
The const-hacks introduces bugs, and they make the code harder to maintain.
Let's wait until we can constify these functions without changing their implementation.
2025-09-12 17:16:38 +02:00
bors
408eacfb95 Auto merge of #146468 - Zalathar:rollup-6u3s44d, r=Zalathar
Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#144549 (match clang's `va_arg` assembly on arm targets)
 - rust-lang/rust#145895 (thread parking: fix docs and examples)
 - rust-lang/rust#146308 (support integer literals in `${concat()}`)
 - rust-lang/rust#146323 (check before test for hardware capabilites in bits 32~63 of usize)
 - rust-lang/rust#146332 (tidy: make behavior of extra-checks more uniform)
 - rust-lang/rust#146374 (Update `browser-ui-test` version to `0.22.2`)
 - rust-lang/rust#146413 (Improve suggestion in case a bare URL is surrounded by brackets)
 - rust-lang/rust#146426 (Bump miow to 0.60.1)
 - rust-lang/rust#146432 (Implement `Socket::take_error` for Hermit)
 - rust-lang/rust#146433 (rwlock tests: fix miri macos test regression)
 - rust-lang/rust#146435 (Change the default value of `gcc.download-ci-gcc` to `true`)
 - rust-lang/rust#146439 (fix cfg for poison test macro)
 - rust-lang/rust#146448 ([rustdoc] Correctly handle literal search on paths)
 - rust-lang/rust#146449 (Fix `libgccjit` symlink when we build GCC locally)
 - rust-lang/rust#146455 (test: remove an outdated normalization for rustc versions)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-09-12 11:27:07 +00:00
Stuart Cook
2e51a38999 Rollup merge of #146439 - connortsui20:fix-sync-macro-attr, r=RalfJung
fix cfg for poison test macro

Fixes test regression in https://github.com/rust-lang/rust/pull/144648
Continuation of https://github.com/rust-lang/rust/pull/146433

I think this is right? Not really sure how to test this myself to be honest.

r? ```@RalfJung```

I'll also leave the improvement to the test macro for a separate PR (described [here](https://github.com/rust-lang/rust/pull/146433#issuecomment-3280210451)) since I've never done something like that before. Though since this fixes all of the tests, it might not be necessary since anyone in the future will see the `cfg()` and not `cfg_attr()`?
2025-09-12 20:02:17 +10:00
Stuart Cook
312e15fb3e Rollup merge of #146433 - RalfJung:rwlock-miri, r=tgross35
rwlock tests: fix miri macos test regression

https://github.com/rust-lang/rust/pull/144648 broke the attributes that ignore the tests on Miri; this patch should fix that.
2025-09-12 20:02:16 +10:00
Stuart Cook
f40d78f57e Rollup merge of #146432 - hermit-os:hermit-take_error, r=joboet
Implement `Socket::take_error` for Hermit

This PR fixes an unused-imports compilation error introduced in 845311a065 and implements `Socket::take_error` for Hermit.

Hermit's `Socket::take_error` implementation works exactly like the one for Unix.

r? joboet
2025-09-12 20:02:15 +10:00
Stuart Cook
1037c082bc Rollup merge of #145895 - RalfJung:unpark, r=joboet
thread parking: fix docs and examples

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

r? ```@joboet```
Cc ```@m-ou-se``` ```@Amanieu```
2025-09-12 20:02:10 +10:00
bors
ac4495a10d Auto merge of #146019 - joboet:better-dlsym, r=tgross35
std: optimize `dlsym!` macro and add a test for it

The `dlsym!` macro always ensures that the name string is nul-terminated, so there is no need to perform the check at runtime. Also, acquire loads are generally faster than a load and a barrier, so use them. This is only false in the case where the symbol is missing, but that shouldn't matter too much.
2025-09-12 08:18:41 +00:00
bors
2a9bacf618 Auto merge of #145177 - joboet:move-pal-thread, r=ibraheemdev
std: move `thread` into `sys`

Part of https://github.com/rust-lang/rust/issues/117276.
2025-09-11 22:31:43 +00:00
Connor Tsui
6354c51d2b update doc comment
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-09-11 13:08:44 -04:00
Connor Tsui
18d0dcbc8e fix config for poison macro test
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-09-11 12:35:26 -04:00
Ralf Jung
092802640f rwlock tests: fix miri macos test regression 2025-09-11 10:04:32 +02:00
Martin Kröning
af5355cc91 Implement Socket::take_error for Hermit 2025-09-11 09:05:17 +02:00
Martin Kröning
9fe101b6ea Remove unused import from sys/pal/hermit/os.rs
This fixes

```
error: unused import: `str`
 --> library/std/src/sys/pal/hermit/os.rs:6:22
  |
6 | use crate::{fmt, io, str};
  |                      ^^^
  |
  = note: `-D unused-imports` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(unused_imports)]`
```

This was caused by 845311a065.
2025-09-11 09:05:17 +02:00
Stuart Cook
c79c990df1 Rollup merge of #146379 - madsmtm:fix-platform_version-test, r=tgross35
Fix `compare_against_sw_vers` test

The `saturating_sub` doesn't actually perform its intended since the version numbers are signed integers (which I changed in a later revision of https://github.com/rust-lang/rust/pull/138944).

Fixes the issue described in https://github.com/rust-lang/rust/pull/138944#issuecomment-3270662876.

r? tgross35
2025-09-11 14:06:29 +10:00
Matthias Krüger
d061896a37 Rollup merge of #146322 - weiznich:fix/146087, r=joboet
Make Barrier RefUnwindSafe again

This commit manually implements `RefUnwindSafe` for `std::sync::Barrier` to fix rust-lang/rust#146087. This is a fix for a regression indroduced by e95db591a4
2025-09-10 20:29:07 +02:00
Matthias Krüger
e79630da0b Rollup merge of #145327 - joboet:net-addr-sgx-hack, r=tgross35
std: make address resolution weirdness local to SGX

Currently, the implementations of `TcpStream::connect` and its cousins take an `io::Result<&SocketAddr>` as argument, which is very weird, as most of them then `?`-try the result immediately to access the actual address. This weirdness is however necessitated by a peculiarity of the SGX networking implementation:

SGX doesn't support DNS resolution but rather accepts hostnames in the same place as socket addresses. So, to make e.g.
```rust
TcpStream::connect("example.com:80")`
```
work, the DNS lookup returns a special error (`NonIpSockAddr`) instead, which contains the hostname being looked up. When `.to_socket_addrs()` fails, the `each_addr` function used to select an address will pass the error to the inner `TcpStream::connect` implementation, which in SGX's case will inspect the error and try recover the hostname from it. If
that succeeds, it continues with the found hostname.

This is pretty obviously a terrible hack and leads to buggy code (for instance, when users use the result of `.to_socket_addrs()` in their own `ToSocketAddrs` implementation to select from a list of possible URLs, the only URL used will be that of the last item tried). Still, without changes to the SGX usercall ABI, it cannot be avoided.

Therefore, this PR aims to minimise the impact of that weirdness and remove it from all non-SGX platforms. The inner `TcpStream::connect`, et al. functions now receive the `ToSocketAddrs` type directly and call `each_addr` (which is moved to `sys::net::connection`) themselves. On SGX, the implementation uses a special `each_addr` which contains the whole pass-hostname-through-error hack.

As well as making the code cleaner, this also opens up the possibility of reusing newly created sockets even if a connection request fails – but I've left that for another PR.

CC `@raoulstrackx`
2025-09-10 20:29:04 +02:00
joboet
4c99219959 std: only test dlsym! on platforms where it is actually used
`dlsym` doesn't work for finding libc symbols on platforms like linux-musl, so the test will fail.
2025-09-10 15:34:38 +02:00
joboet
ad08577a50 std: move thread into sys 2025-09-10 15:26:17 +02:00
Georg Semmler
ef7b036458 Add suggestions 2025-09-10 07:55:03 +02:00
Mads Marquart
23edc4dd42 Fix compare_against_sw_vers test when a version part is 0 2025-09-09 19:43:50 +02:00
Matthias Krüger
542130f729 Rollup merge of #146366 - LorrensP-2158466:miri-gamma, r=RalfJung
add approx_delta to all gamma tests

f32::gamma tests are less precise in CI, so we increase the tolerance for these tests. See [#miri > Miri test-libstd Failure (2025-09) @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/269128-miri/topic/Miri.20test-libstd.20Failure.20.282025-09.29/near/538138742)

r? `@RalfJung`
2025-09-09 17:32:23 +02:00
Georg Semmler
30fd32eca5 Make the compile test use a const instead 2025-09-09 17:14:38 +02:00
Georg Semmler
20d02258fc Make Barrier RefUnwindSafe again
This commit manually implements `RefUnwindSafe` for
`std::sync::Barrier` to fix 146087. This is a fix for a regression
indroduced by e95db591a4
2025-09-09 17:13:38 +02:00
LorrensP-2158466
c4cbb54f3f add approx_delta to all gamma tests 2025-09-09 09:49:48 +02:00
Stuart Cook
8b9ea589fb Rollup merge of #146343 - madsmtm:fix-platform_version, r=tgross35
Weakly export `platform_version` symbols

The symbols `__isPlatformVersionAtLeast` and `__isOSVersionAtLeast`. This should allow linking both `compiler-rt` and `std`, which fixes https://github.com/rust-lang/rust/pull/138944#issuecomment-3266574582.

r? tgross35
CC ``@zmodem,`` could you please verify that this works for you?
2025-09-09 14:35:07 +10:00
Mads Marquart
fe6f8cc6f5 Weakly export platform_version symbols
The symbols __isPlatformVersionAtLeast and __isOSVersionAtLeast.

This allows the user to link both compiler_rt and std.
2025-09-08 20:10:43 +02:00
Mads Marquart
d51f0ea172 Reorder test to make failures clearer 2025-09-08 20:10:43 +02:00
joboet
4b15dd5a84 std: move thread into sys (rename only) 2025-09-08 17:02:25 +02:00
joboet
207a01e88f std: make address resolution weirdness local to SGX 2025-09-08 16:58:43 +02:00
Matthias Krüger
d1ab870a07 Rollup merge of #146299 - smirzaei:doc/improve-path-canonicalize-docs, r=jhpratt
docs(std): add error docs for path canonicalize

This PR adds the missing error documentation for both [Path.canonicalize](https://doc.rust-lang.org/std/path/struct.Path.html#method.canonicalize) and [PathBuf.canonicalize](https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.canonicalize) methods. Since both methods are wappers around [fs::canonicalize](https://doc.rust-lang.org/std/fs/fn.canonicalize.html), the error doc is copied directly from that function.

This makes it faster to find what errors might arise when calling `path.canonicalize` or `path_buf.canonicalize` in the editor itself without needing to drill down to the  `fs::canonicalzie` docs.
2025-09-08 16:34:57 +02:00
Matthias Krüger
e4e4829579 Rollup merge of #146269 - weihanglo:solaris-flock, r=Mark-Simulacrum
feat(std): emulate flock for solaris via fcntl

Upstream Solaris flock emulation to libstd from cargo.

This is borrowed from
3b379fcc54/src/cargo/util/flock.rs (L502-L536) which was implemented by an Oracle employee.
The code has been in cargo since 2022-12.

Python's `fcntl.flock` emulates like this as well: c919d02ede/Modules/fcntlmodule.c (L337-L400)

We did the same thing in
0d0f4eac8b/compiler/rustc_data_structures/src/flock/unix.rs (L13-L39)

However, should we just always falls back to fcntl for all Unix, instead of "unsupported"?

try-job: `*-solaris`
2025-09-07 20:02:28 +02:00
Soroush Mirzaei
4b5d0e02ca docs(std): add error docs for path canonicalize 2025-09-07 11:17:59 -04:00
bors
f13ef0d75d Auto merge of #146216 - LorrensP-2158466:miri-float-nondet-foreign-items-take2, r=RalfJung
Miri: non-deterministic floating point operations in foreign_items

Take 2 of rust-lang/rust#143906. The last 2 commits are what changed compared to the original pr.

Verified the tests using (fish shell):
```fish
env MIRIFLAGS="-Zmiri-max-extra-rounding-error -Zmiri-many-seeds" ./x miri --no-fail-fast std core coretests  -- f32 f64
```

r? `@RalfJung`
2025-09-07 10:46:38 +00:00
Weihang Lo
01edb24d3c feat(std): emulate flock for solaris via fcntl
Upstream Solaris flock emulation to libstd from cargo.

This is borrowed from
3b379fcc54/src/cargo/util/flock.rs (L502-L536)
which was implemented by an Oracle employee.
The code has been in cargo since 2022-12.

Python's `fcntl.flock` emulates like this as well:
c919d02ede/Modules/fcntlmodule.c (L337-L400)

We did the same thing in
0d0f4eac8b/compiler/rustc_data_structures/src/flock/unix.rs (L13-L39)
2025-09-07 00:05:13 -04:00
LorrensP-2158466
e7e06aca38 Change stdlib float tests to account for miri nondet floats. 2025-09-06 21:45:17 +02:00
Trevor Gross
31d7cbc371 Rollup merge of #139524 - Berrysoft:cygwin-socket-ext, r=tgross35
Add socket extensions for cygwin

r? `@joboet`

* Abstract name uds addr
* quickack
* passcred
2025-09-06 14:39:04 -04:00
Berrysoft
26b1575722 Add socket extensions for cygwin 2025-09-06 20:23:37 +08:00
Trevor Gross
e2698f8c36 Rollup merge of #146257 - alexcrichton:update-wasi-crate, r=tgross35
std: Update `wasi` crate dependency

The recent work on the WASIp2 target being integrated into the standard library (rust-lang/rust#146207, rust-lang/rust#145944) ended up causing a bug in nightly on the target. This [has now been fixed](https://github.com/bytecodealliance/wasi-rs/pull/115) in the `wasi` crate so this commit pulls in the updated version to ensure bindings work correctly.
2025-09-05 20:10:01 -04:00
Alex Crichton
874dbd5d57 std: Update wasi crate dependency
The recent work on the WASIp2 target being integrated into the standard
library ended up causing a bug in nightly on the target. This has now
been fixed in the `wasi` crate so this commit pulls in the updated
version to ensure bindings work correctly.
2025-09-05 17:01:07 -07:00
León Orell Valerian Liehr
349fbba24f Rollup merge of #138944 - madsmtm:apple_os_version_check, r=tgross35
Add `__isPlatformVersionAtLeast` and `__isOSVersionAtLeast` symbols

## Motivation

When Objective-C code uses ```@available(...)`,`` Clang inserts a call to [`__isPlatformVersionAtLeast`](https://github.com/llvm/llvm-project/blob/llvmorg-20.1.0/compiler-rt/lib/builtins/os_version_check.c#L276) (`__isOSVersionAtLeast` in older Clang versions). These symbols not being available sometimes ends up causing linker errors. See the new test `tests/run-make/apple-c-available-links` for a minimal reproducer.

The workaround is to link `libclang_rt.osx.a`, see e.g. https://github.com/alexcrichton/curl-rust/issues/279. But that's very difficult for users to figure out (and the backreferences to that issue indicates that people are still running into this in their own projects every so often).

For another recent example, this is preventing `rustc` from using LLVM assertions on macOS, see https://github.com/rust-lang/rust/pull/62592#issuecomment-510670657 and https://github.com/rust-lang/rust/pull/134275#issuecomment-2543067830.

It is also a blocker for [setting the correct minimum OS version in `cc-rs`](https://github.com/rust-lang/rust/issues/136113), since fixing this in `cc-rs` might end up introducing linker errors in places where we weren't before (by default, if using e.g. ```@available(macos`` 10.15, *)`, the symbol usually happens to be left out, since `clang` defaults to compiling for the host macOS version, and thus things _seem_ to work - but the availability check actually compiles down to nothing, which is a huge correctness footgun for running on older OSes).

(My super secret evil agenda is also to expose some variant of ```@available``` in Rust's `std` after https://github.com/rust-lang/rfcs/pull/3750 progresses further, will probably file an ACP for this later. But I believe this PR has value regardless of those future plans, since we'd be making C/Objective-C/Swift interop easier).

## Solution

Implement `__isPlatformVersionAtLeast` and `__isOSVersionAtLeast` as part of the "public ABI" that `std` exposes.

**This is insta-stable**, in the same sense that additions to `compiler-builtins` are insta-stable, though the availability of these symbols can probably be considered a "quality of implementation" detail rather than a stable promise.

I originally proposed to implement this in `compiler-builtins`, see https://github.com/rust-lang/compiler-builtins/pull/794, but we discussed moving it to `std` instead ([Zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Provide.20.60__isPlatformVersionAtLeast.60.20in.20.60std.60.3F/with/507880717)), which makes the implementation substantially simpler, and we avoid gnarly issues with requiring the user to link `libSystem.dylib` (since `std` unconditionally does that).

Note that this does not solve the linker errors for (pure) `#![no_std]` users, but that's _probably_ fine, if you are using ```@available``` to test the OS version on Apple platforms, you're likely also using `std` (and it is still possible to work around by linking `libclang_rt.*.a`).

A thing to note about the implementation, I've choosen to stray a bit from LLVM's upstream implementation, and not use `_availability_version_check` since [it has problems when compiling with an older SDK](https://github.com/llvm/llvm-project/issues/64227). Instead, we use `sysctl kern.osproductversion` when available to still avoid the costly PList lookup in most cases, but still with a fall back to the PList lookup when that is not available (with the PList fallback being is similar to LLVM's implementation).

## Testing

Apple has a lot of different "modes" that they can run binaries in, which can be a bit difficult to find your bearings in, but I've tried to be as thorough as I could in testing them all.

Tested using roughly the equivalent of `./x test library/std -- platform_version` on the following configurations:
- macOS 14.7.3 on a Macbook Pro M2
    - `aarch64-apple-darwin`
    - `x86_64-apple-darwin` (under Rosetta)
    - `aarch64-apple-ios-macabi`
    - `x86_64-apple-ios-macabi` (under Rosetta)
    - `aarch64-apple-ios` (using Xcode's "Designed for iPad" setting)
    - `aarch64-apple-ios-sim` (in iOS Simulator, as iPhone with iOS 17.5)
    - `aarch64-apple-ios-sim` (in iOS Simulator, as iPad with iOS 18.2)
    - `aarch64-apple-tvos-sim` (in tvOS Simulator)
    - `aarch64-apple-watchos-sim` (in watchOS Simulator)
    - `aarch64-apple-ios-sim` (in visionOS simulator, using Xcode's "Designed for iPad" setting)
    - `aarch64-apple-visionos-sim` (in visionOS Simulator)
- macOS 15.3.1 VM
    - `aarch64-apple-darwin`
    - `aarch64-apple-ios-macabi`
- macOS 10.12.6 on an Intel Macbook from 2013
    - `x86_64-apple-darwin`
    - `i686-apple-darwin`
    - `x86_64-apple-ios` (in iOS Simulator)
- iOS 9.3.6 on a 1st generation iPad Mini
    - `armv7-apple-ios` with an older compiler

Along with manually inspecting the output of `version_from_sysctl()` and `version_from_plist()`, and verifying that they actually match what's expected.

I believe the only real omissions here would be:
- `aarch64-apple-ios` on a newer iPhone that has `sysctl` available (iOS 11.4 or above).
- `aarch64-apple-ios` on a Vision Pro using Xcode's "Designed for iPad" setting.

But I don't have the hardware available to test those.

``@rustbot`` label O-apple A-linkage -T-compiler -A-meta -A-run-make

try-job: aarch64-apple
2025-09-05 22:47:17 +02:00
Mads Marquart
846d6a4466 Add __isOSVersionAtLeast and __isPlatformVersionAtLeast symbols
Allows users to link to Objective-C code using `@available(...)`.
2025-09-05 16:18:49 +02:00
Trevor Gross
7fc547c4f2 Rollup merge of #146207 - alexcrichton:wasip2-stdio, r=juntyr
std: Implement WASIp2-specific stdio routines

This commit is an extension of rust-lang/rust#145944 but applied to stdio specifically. The stdio routines are updated away from WASIp1 APIs to using WASIp2 APIs natively. The end goal is to eventually drop the dependency on WASIp1 APIs in the standard library entirely in favor of exclusively depending on WASIp2.
2025-09-05 01:53:22 -04:00
Alex Crichton
d8ca776f6d std: Implement WASIp2-specific stdio routines
This commit is an extension of previous libstd support but applied to stdio
specifically. The stdio routines are updated away from WASIp1 APIs to using
WASIp2 APIs natively. The end goal is to eventually drop the dependency on
WASIp1 APIs in the standard library entirely in favor of exclusively depending
on WASIp2.
2025-09-04 09:15:10 -07:00
Matthias Krüger
60196de4c2 Rollup merge of #146194 - bend-n:fix-path-str-eq, r=ibraheemdev
fix path str eq

fixes rust-lang/rust#146183
where the impl for partialeq<str> for pathbuf resulted in infinite recursion
2025-09-04 17:45:49 +02:00