Commit Graph

134 Commits

Author SHA1 Message Date
Stuart Cook
eda6dc9283 Rollup merge of #144651 - connortsui20:nonpoison_condvar, r=joboet
Implementation: `#[feature(nonpoison_condvar)]`

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

This PR continues the effort made in https://github.com/rust-lang/rust/pull/144022 by adding the implementation of `nonpoison::condvar`.

Many of the changes here are similar to the changes made to implement `nonpoison::mutex`.

There are two other changes here. The first is that the `Barrier` implementation is migrated to use the `nonpoison::Condvar` instead of the `poison` variant. The second (which might be subject to some discussion) is that `WaitTimeoutResult` is moved up to `mod.rs`, as both `condvar` variants need that type (and I do not know if there is a better place to put it now).

### Related PRs

- `nonpoison_rwlock` implementation: https://github.com/rust-lang/rust/pull/144648
- `nonpoison_once` implementation: https://github.com/rust-lang/rust/pull/144653
2025-08-30 20:29:06 +10:00
Jacob Pratt
d5340c26fa Rollup merge of #145307 - connortsui20:lazylock-poison-msg, r=Amanieu
Fix `LazyLock` poison panic message

Fixes the issue raised in https://github.com/rust-lang/rust/pull/144872#issuecomment-3151100248

r? ```@Amanieu```
2025-08-23 23:58:35 -04:00
Connor Tsui
b2380d2bcc add nonpoison and poison condvar tests
Adds tests for the `nonpoison::Mutex` variant by using a macro to
duplicate the existing `poison` tests.

Note that all of the tests here are adapted from the existing `poison`
tests.

Also steals the `test_mutex_arc_condvar` test from `mutex.rs`.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-08-23 09:20:44 -04:00
Jacob Pratt
2bd39222cd Rollup merge of #144648 - connortsui20:nonpoison_rwlock, r=Mark-Simulacrum
Implementation: `#[feature(nonpoison_rwlock)]`

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

This PR continues the effort made in https://github.com/rust-lang/rust/pull/144022 by adding the implementation of `nonpoison::rwlock`.

Many of the changes here are similar to the changes made to implement `nonpoison::mutex`. The only real difference is that this PR includes a reorganizing of the existing `poison::rwlock` file that hopefully makes both variants more readable.

### Related PRs

- `nonpoison_condvar` implementation: https://github.com/rust-lang/rust/pull/144651
- `nonpoison_once` implementation: https://github.com/rust-lang/rust/pull/144653
2025-08-22 22:00:46 -04:00
Connor Tsui
06eb782c4e modify LazyLock poison panic message
Fixes an issue where if the underlying `Once` panics because it is
poisoned, the panic displays the wrong message.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-08-22 14:59:34 -04:00
Stuart Cook
d0fa5c7af7 Rollup merge of #144960 - raoulstrackx:raoul/rte-513-disable_sleep_tests_on_sgx, r=Mark-Simulacrum
[RTE-513] Ignore sleep_until test on SGX

rust-lang/rust#141829 added a test for `sleep_until`: it checks whether its specification holds:
> Puts the current thread to sleep until the specified deadline has passed.

but in SGX there's no secure time source. There's only the ability to request the `insecure_time` from outside of the enclave through a [usercall](https://github.com/fortanix/rust-sgx/blob/master/intel-sgx/fortanix-sgx-abi/src/lib.rs#L590-L592) and the ability to [wait](https://github.com/rust-lang/rust/blob/master/library/std/src/sys/pal/sgx/abi/usercalls/mod.rs#L173-L179) for a certain event or timeout. But both are under the control of an attacker; users should not depend on the accuracy nor correctness of this time. We try to even enforce this by adding a +/-10% time interval to wait usercalls.

The current `thread::sleep_until` implementation uses this `wait` usercall. When a negative randomization interval is added to the timeout passed in `wait`, the test fails. As users should not rely on the correctness of any time inside the enclave, it should be considered an incorrect test on SGX. This PR ignores this test.
2025-08-19 14:18:21 +10:00
Josh Triplett
1ae4a0cc34 library: Migrate from cfg_if to cfg_select
Migrate the standard library from using the external `cfg_if` crate to
using the now-built-in `cfg_select` macro.

This does not yet eliminate the dependency from
`library/std/Cargo.toml`, because while the standard library itself no
longer uses `cfg_if`, it also incorporates the `backtrace` crate, which
does.

Migration assisted by the following vim command (after selecting the
full `cfg_if!` invocation):

```
'<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e
```

This is imperfect, but substantially accelerated the process. This
prompts for confirmation on the `} else {` since that can also appear
inside one of the arms. This also requires manual intervention to handle
any multi-line conditions.
2025-08-16 05:28:31 -07:00
Jakub Beránek
ff44871be5 Rollup merge of #144870 - Kivooeo:file_prefix-stabilize, r=tgross35
Stabilize `path_file_prefix` feature

This stabilises `Path::file_prefix`, following the FCP in [tracking issue ](https://github.com/rust-lang/rust/issues/86319)

(FCP ended almost a year ago, so if it's needed for proccess we could rerun it)

Closes: https://github.com/rust-lang/rust/issues/86319
2025-08-13 07:03:47 +02:00
Esteban Küber
74c3727b1f Remove unnecessary parentheses in assert!s 2025-08-10 21:59:04 +00:00
Connor Tsui
ad499d076a add nonpoison and poison rwlock tests
Adds tests for the `nonpoison::RwLock` variant by using a macro to
duplicate the existing `poison` tests.

Note that all of the tests here are adapted from the existing `poison`
tests.
2025-08-09 08:41:27 +02:00
Connor Tsui
d8a0df075d reorganize rwlock tests
This commit simply helps discern the actual changes needed to test both
poison and nonpoison `rwlock`s.
2025-08-09 08:41:27 +02:00
Jakub Beránek
8fcfbcd868 Revert "Rollup merge of #143906 - LorrensP-2158466:miri-float-nondet-foreign-items, r=RalfJung"
This reverts commit 71f04692c3, reversing
changes made to 995ca3e532.
2025-08-08 19:16:48 +02:00
Stuart Cook
71f04692c3 Rollup merge of #143906 - LorrensP-2158466:miri-float-nondet-foreign-items, r=RalfJung
Miri: non-deterministic floating point operations in `foreign_items`

Part of [rust-lang/miri/#3555](https://github.com/rust-lang/miri/issues/3555#issue-2278914000), this pr does the `foreign_items` work.

Some things have changed since rust-lang/rust#138062 and rust-lang/rust#142514. I moved the "helpers" used for creating fixed outputs and clamping operations to their defined ranges to `math.rs`. These are now also extended to handle the floating-point operations in `foreign_items`. Tests in `miri/tests/float.rs` were changed/added.

Failing tests in `std` were extracted, run under miri with `-Zmiri-many-seeds=0..1000` and changed accordingly. Double checked with `-Zmiri-many-seeds`.

I noticed that the C standard doesn't specify the output ranges for all of its mathematical operations; it just specifies them as:
```
Returns
The sinh functions return sinh x.
```
So I used [Wolfram|Alpha](https://www.wolframalpha.com/).
2025-08-07 20:49:41 +10:00
LorrensP-2158466
71add2f5f7 Change stdlib float tests to account for miri nondet floats. 2025-08-06 17:21:04 +02:00
Raoul Strackx
3a993a611c Ignore sleep_until test on SGX 2025-08-05 14:51:39 +02:00
Kivooeo
4c4b8b23c6 remove gate 2025-08-04 02:18:18 +05:00
Connor Tsui
d073d297b6 add extra drop, panic, and unwind tests 2025-07-29 10:44:36 +02:00
Connor Tsui
3eb722e655 add nonpoison and poison mutex tests
Adds tests for the `nonpoison::Mutex` variant by using a macro to
duplicate the existing `poison` tests.

Note that all of the tests here are adapted from the existing `poison`
tests.
2025-07-29 10:36:26 +02:00
Connor Tsui
f34fb05923 reorder mutex tests
This commit simply helps discern the actual changes needed to test both
poison and nonpoison locks.
2025-07-29 10:33:05 +02:00
bors
ca98d4d4b3 Auto merge of #141829 - dvdsk:sleep_until_linux, r=cuviper,RalfJung
Specialize sleep_until implementation for unix (except mac)

related tracking issue: https://github.com/rust-lang/rust/issues/113752
Supersedes https://github.com/rust-lang/rust/pull/118480 for the reasons see: https://github.com/rust-lang/rust/issues/113752#issuecomment-2902594469

Replaces the generic catch all implementation with target_os specific ones for: linux/netbsd/freebsd/android/solaris/illumos etc. Other platforms like wasi, macos/ios/tvos/watchos and windows will follow in later separate PR's (once this is merged).
2025-07-06 23:00:51 +00:00
dvdsk
f24ee2c9b1 sleep_until: use clock_nanosleep where possible
Using clock nanosleep leads to more accurate sleep times on platforms
where it is supported.

To enable using clock_nanosleep this makes `sleep_until` platform
specific. That unfortunatly requires identical placeholder
implementations for the other platforms (windows/mac/wasm etc).

we will land platform specific implementations for those later. See the
`sleep_until` tracking issue.

This requires an accessors for the Instant type. As that accessor is only
used on the platforms that have clock_nanosleep it is marked as allow_unused.

32bit time_t targets do not use clock_nanosleep atm, they instead rely
on the same placeholder as the other platforms. We could make them
use clock_nanosleep too in the future using `__clock_nanosleep_time64`.

__clock_nanosleep_time64 is documented at:
https://www.gnu.org/software/libc/manual/html_node/64_002dbit-time-symbol-handling.html
2025-07-06 17:36:49 +02:00
klensy
c76d032f01 setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
Folkert de Vries
1dfc8406dc make tidy-alphabetical use a natural sort 2025-06-25 22:52:38 +02:00
bors
8de4c7234d Auto merge of #141864 - Berrysoft:cygwin-path, r=ChrisDenton
Handle win32 separator for cygwin paths

This PR handles a issue that cygwin actually supports Win32 path, so we need to handle the Win32 prefix and separaters.

r? `@mati865`

cc `@jeremyd2019`

~~Not sure if I should handle the prefix like the windows target... Cygwin *does* support win32 paths directly going through the APIs, but I think it's not the recommended way.~~

Here I just use `cygwin_conv_path` because it handles both cygwin and win32 paths correctly and convert them into absolute POSIX paths.

UPDATE: Windows path prefix is handled.
2025-06-19 13:38:37 +00:00
Jubilee Young
66e056a3a7 library: Increase timeout on mpmc test to reduce flakes
This recently spuriously failed in a rollup, so I think we can afford to
increase the base timeout and the amount of time slept for to provide
a much wider margin for the timeout to be reached.
2025-06-17 16:10:37 -07:00
王宇逸
3cb0cba054 Handle win32 separator & prefixes for cygwin paths 2025-06-16 09:24:07 +08:00
bors
c6768de2d6 Auto merge of #138062 - LorrensP-2158466:miri-enable-float-nondet, r=RalfJung
Enable Non-determinism of float operations in Miri and change std tests

Links to [#4208](https://github.com/rust-lang/miri/issues/4208) and [#3555](https://github.com/rust-lang/miri/issues/3555) in Miri.

Non-determinism of floating point operations was disabled in rust-lang/rust#137594 because it breaks the tests and doc-tests in core/coretests and std. This PR enables some of them.

This pr includes the following changes:

- Enables the float non-determinism but with a lower relative error of 4ULP instead of 16ULP
- These operations now have a fixed output based on the C23 standard, except the pow operations, this is tracked in [#4286](https://github.com/rust-lang/miri/issues/4286#issue-3010677983)
- Changes tests that made incorrect assumptions about the operations, not to make that assumption anymore (from `assert_eq!` to `assert_approx_eq!`.
- Changed the doctests of the stdlib of these operations to compare against fixed constants instead of `f*::EPSILON`, which now succeed with Miri and `-Zmiri-many-seeds`
- Added a constant `APPROX_DELTA` in `std/tests/floats/f32.rs` which is used for approximation tests, but with a different value when run in Miri. This is to make these tests succeed.
- Added tests in the float tests of Miri to test the C23 behaviour.

Fixes https://github.com/rust-lang/miri/issues/4208
2025-06-09 21:21:58 +00:00
Josh Triplett
889f7cbffa Avoid a gratuitous 10s wait in a stress test
`stress_recv_timeout_two_threads`, in the mpmc and mpsc testsuites,
is a stress test of the `recv_timeout` function. This test processes and
ignores timeouts, and just ensures that every sent value gets received.
As such, the exact length of the timeouts is not critical, only that
the timeout and sleep durations ensure that at least one timeout
occurred.

The current tests have 100 iterations, half of which sleep for 200ms,
causing the test to take 10s. This represents around 2/3rds of the
*total* runtime of the `library/std` testsuite.

Reduce this to 50 iterations where half of them sleep for 10ms, causing
the test to take 0.25s.

Add a check that at least one timeout occurred.
2025-06-08 20:22:07 -07:00
schvv31n
eba3a61067 Stabilised os_string_pathbuf_leak 2025-06-06 12:06:42 -07:00
LorrensP-2158466
00452bd783 change tests to use fixed constants to let them pass with miri 2025-06-05 16:22:13 +02:00
LorrensP-2158466
5bafe9d8fc Enable Float non-determinism in miri. Update and add tests and change
change tests in std, core and coretests.
2025-06-03 19:46:13 +02:00
Chris Denton
c299e297ee Implement normalize lexically 2025-05-25 08:11:41 +00:00
Guillaume Gomez
284aaee0c1 Rollup merge of #141105 - GrantBirki:grantbirki/path-tests, r=jhpratt
additional edge cases tests for `path.rs` 🧪

This pull request adds a few new edge case tests to the `std::path` module. The new tests cover scenarios such as paths with only separators, non-ASCII and Unicode characters, embedded new lines, etc. Each new test is documented with some helpful in-line comments as well.
2025-05-24 21:23:48 +02:00
GrantBirki
4358a1c05e remove extra tests that really might not be all that useful 2025-05-17 10:49:15 -07:00
GrantBirki
1bc8535e61 revert forward slash to backslash 2025-05-17 10:36:39 -07:00
GrantBirki
604f0e2743 remove test_embedded_null_byte() test for now 2025-05-16 22:42:05 -07:00
GrantBirki
49658e6a3c additional edge cases tests for path.rs 2025-05-16 15:19:44 -07:00
Trevor Gross
2b9256e1c8 Move applicable float tests from coretests back to std
The previous commit moved all test files from `std` to `core` so git
understands the move. Not all functionality is actually testable in
`core`, however, so perform move the relevant portions back. Changes
from inherent to module methods is also done since this is the form of
math operations available in `core` (as `core_float_math`).
2025-05-14 14:29:58 +00:00
Trevor Gross
48f3e63f70 Move float tests from std to core
Many float-related tests in `std` only depend on `core`, so move the
tests there. This also allows us to verify functions from
`core_float_math`.

Since the majority of test files need to be moved to `coretests`, move
the files here without any cleanup; this is done in a followup commit.
This makes git history slightly cleaner, but coretests will not build
immediately after this commit.
2025-05-13 22:22:15 +00:00
Pietro Albini
2ce08ca5d6 update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
Zachary S
d2068be4a0 Rename (Mapped)(RwLock|Mutex)Guard::try_map to filter_map.
1. analogous to std::cell::Ref(Mut)::filter_map.
2. doesn't imply `Try` genericizability.
2025-04-30 19:43:24 -05:00
Trevor Gross
dfa972e454 Use feature(target_has_reliable_f16_f128) in library tests
New compiler configuration has been introduced that is designed to
replace the build script configuration `reliable_f16`, `reliable_f128`,
`reliable_f16_math`, and `reliable_f128_math`. Do this replacement here,
which allows us to clean up `std`'s build script.

All tests are gated by `#[cfg(bootstrap)]` rather than doing a more
complicated `cfg(bootstrap)` / `cfg(not(bootstrap))` split since the
next beta split is within two weeks.
2025-04-27 20:10:33 +00:00
Ralf Jung
e7a865448a test_nan: ensure the NAN contant is quiet 2025-04-22 09:06:43 +02:00
Glyn Normington
1376810d44 Basic tests of MPMC receiver cloning
Ref: https://github.com/rust-lang/rust/issues/126840#issuecomment-2802321146
2025-04-15 02:37:57 +01:00
Stuart Cook
92bb7261c4 Rollup merge of #137897 - xTachyon:tls-fix, r=thomcc,jieyouxu
fix pthread-based tls on apple targets

Tries to fix #127773.
2025-04-05 13:18:13 +11:00
Calder Coalson
8ff70529f2 Expose algebraic floating point intrinsics 2025-04-04 16:13:57 -07:00
Matthias Krüger
53076de369 Rollup merge of #138294 - paulmenage:test-panic-unwind, r=bjorn3
Mark some std tests as requiring `panic = "unwind"`

This allows these test modules to pass on builds/targets without unwinding support, where `panic = "abort"` - the ignored tests are for functionality that's not supported on those targets.
2025-03-22 21:34:36 +01:00
Andrei Damian
e41cce03a0 fix pthread-based tls on apple targets 2025-03-18 20:31:52 +02:00
Jacob Pratt
62c2a7b93b Rollup merge of #137793 - NobodyXu:stablise-annoymous-pipe, r=joshtriplett
Stablize anonymous pipe

Since #135822 is staled, I create this PR to stablise anonymous pipe

Closes #127154

try-job: test-various
2025-03-17 05:47:50 -04:00
bors
c3dd4eefd6 Auto merge of #138363 - beetrees:f16-f128-integer-convert, r=Amanieu
Add `From<{integer}>` for `f16`/`f128` impls

This PR adds `impl From<{bool,i8,u8}> for f16` and `impl From<{bool,i8,u8,i16,u16,i32,u32}> for f128`.

The `From<{i64,u64}> for f128` impls are left commented out as adding them would allow using `f128` on stable before it is stabilised like in the following example:
```rust
fn f<T: From<u64>>(x: T) -> T { x }

fn main() {
    let x = f(1.0); // the type of the literal is inferred to be `f128`
}
```
None of the impls added in this PR have this issue as they are all, at minimum, also implemented by `f64`.

This PR will need a crater run for the `From<{i32,u32}>` impls, as `f64` is no longer the only float type to implement them (similar to the cause of #125198).

cc `@bjoernager`
r? `@tgross35`

Tracking issue: #116909
2025-03-17 00:33:36 +00:00