Commit Graph

193 Commits

Author SHA1 Message Date
Ayush Singh c37e44879e std: tests: env: Add split_paths_uefi
- Add test for split_paths for UEFI target.
- `;` is the path separator. Escaping is not supported.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2026-02-26 23:11:40 +05:30
Stuart Cook 6bcb461903 Rollup merge of #149783 - folkertdev:stabilize-cfg-select, r=JonathanBrouwer
stabilize `cfg_select!`

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/149783)*

tracking issue: https://github.com/rust-lang/rust/issues/115585
closes https://github.com/rust-lang/rust/issues/115585
reference PR:

- https://github.com/rust-lang/reference/pull/2103

# Request for Stabilization

## Summary

The `cfg_select!` macro picks the expansion corresponding to the first `cfg` condition that evaluates to `true`. It simplifies complex conditional expressions.

```rust
cfg_select! {
    unix => {
        fn foo() { /* unix specific functionality */ }
    }
    target_pointer_width = "32" => {
        fn foo() { /* non-unix, 32-bit functionality */ }
    }
    _ => {
        fn foo() { /* fallback implementation */ }
    }
}

let is_unix_str = cfg_select! {
    unix => "unix",
    _ => "not unix",
};
println!("{is_unix_str}");
```
## Semantics

The expansion of a `cfg_select!` call is the right-hand side of the first `cfg` rule that evaluates to true.

This can be roughly expressed using this macro:
```rust
macro_rules! cfg_select {
    ({ $($tt:tt)* }) => {{
        $crate::cfg_select! { $($tt)* }
    }};
    (_ => { $($output:tt)* }) => {
        $($output)*
    };
    (
        $cfg:meta => $output:tt
        $($( $rest:tt )+)?
    ) => {
        #[cfg($cfg)]
        $crate::cfg_select! { _ => $output }
        $(
            #[cfg(not($cfg))]
            $crate::cfg_select! { $($rest)+ }
        )?
    }
}
```

The actual implementation uses a builtin macro so that `cfg_select!` can be used both in item and expression position.

## Documentation

reference PR:

- https://github.com/rust-lang/reference/pull/2103

## Tests

The `cfg_select!` macro is already used extensively in the rust compiler codebase. It has several dedicated tests:

- [`tests/ui/check-cfg/cfg-select.rs`](https://github.com/rust-lang/rust/blob/main/tests/ui/check-cfg/cfg-select.rs)tests that warnings are emitted when an unexpected `cfg` condition is used.
- [`tests/ui/macros/cfg_select.rs`](https://github.com/rust-lang/rust/blob/main/tests/ui/macros/cfg_select.rs) tests that `cfg_select!` has the expected expansion, and tests that the expected syntax is accepted.
## History

- rust-lang/rust#115416
- rust-lang/rust#117162
- rust-lang/rust#133720
- rust-lang/rust#135625
- rust-lang/rust#137198
- rust-lang/rust#138993
- rust-lang/rust#138996
- rust-lang/rust#143461
- rust-lang/rust#143941
- rust-lang/rust#145233
- rust-lang/rust#148712
- rust-lang/rust#149380
- https://github.com/rust-lang/rust/pull/149925

# Resolved questions

# Unresolved questions

The style team has decided on how to format `cfg_select!`, but this formatting has not yet been implemented. See https://github.com/rust-lang/rust/pull/144323.

r? @traviscross

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_CONCERN-ISSUE_START -->

> [!NOTE]
> # Concerns (0 active)
>
> - ~~[allowing-comma-after-closing-brace](https://github.com/rust-lang/rust/pull/149783#issuecomment-3808533494)~~ resolved in [this comment](https://github.com/rust-lang/rust/pull/149783#issuecomment-3882251672)
>
> *Managed by `@rustbot`—see [help](https://forge.rust-lang.org/triagebot/concern.html) for details.*

<!-- TRIAGEBOT_CONCERN-ISSUE_END -->
<!-- TRIAGEBOT_END -->
2026-02-23 13:31:59 +11:00
Folkert de Vries 14d29f9ae2 Stabilize cfg_select 2026-02-22 19:59:25 +01:00
Jonathan Brouwer 3ed70babac Rollup merge of #152865 - asder8215:path_display, r=joboet
Fixed ByteStr not padding within its Display trait when no specific alignment is mentioned

Fixes rust-lang/rust#152804. `Path`'s `Display` uses `ByteStr`'s `Display`, which is where the problem was occurring.

The issue was coming from `ByteStr` implementation of `fmt()` in this particular area:
```rust
        let Some(align) = f.align() else {
            return fmt_nopad(self, f);
        };
        let nchars: usize = self
            .utf8_chunks()
            .map(|chunk| {
                chunk.valid().chars().count() + if chunk.invalid().is_empty() { 0 } else { 1 }
            })
            .sum();
        let padding = f.width().unwrap_or(0).saturating_sub(nchars);
        let fill = f.fill();
        let (lpad, rpad) = match align {
            fmt::Alignment::Left => (0, padding),
            fmt::Alignment::Right => (padding, 0),
            fmt::Alignment::Center => {
                let half = padding / 2;
                (half, half + padding % 2)
            }
        };
```

The docs for the align implies that `Alignment::Left`, `Alignment::Right`, `Alignment::Center` comes from `:<`, `:>`, and `:^` respectively with `align()` returning `None` if neither of those symbols are used in the formatted string. However, while padding is taken care of in the aligned cases, we could still have padding for things that don't use alignment like:
```rust
assert_eq!(format!("{:10}", Path::new("/foo/bar").display()), "/foo/bar  ");
```
We shouldn't write to `f` and return from there when there's no alignment; we should also include any potential padding/filling bytes here.

r? @joboet
2026-02-22 11:31:13 +01:00
Mahdi Ali-Raihan d6ff921cd9 Fixed ByteStr not padding within its Display trait when no specific alignment is not mentioned (e.g. ':10' instead of ':<10', ':>10', or ':^1') 2026-02-20 17:46:14 -05:00
Zalathar d02743e2fd Remove two more flaky assertions from oneshot tests 2026-02-20 12:48:27 +11:00
cyrgani 28fc413c8f remove #![allow(stable_features)] from most tests 2026-02-17 08:45:08 +00:00
Jacob Pratt 1dd933c37e Rollup merge of #152648 - JonathanBrouwer:debug_spurious, r=jhpratt
Remove timing assertion from `oneshot::send_before_recv_timeout`

This test regularly spuriously fails in CI, such as https://github.com/rust-lang/rust/pull/152632#issuecomment-3902778366
We can just remove the assertion but I'd like to understand why, so I'm adding more information to the assert
2026-02-16 04:28:58 -05:00
xonx 2c1d605f21 unify and deduplicate floats 2026-02-15 18:00:41 +00:00
Jonathan Brouwer dab350a3ed Remove timing assertion from oneshot::send_before_recv_timeout 2026-02-15 12:32:17 +01:00
Jacob Pratt 3ce7fb6607 Rollup merge of #152534 - PaulDance:patches/remove-win7-uds, r=Mark-Simulacrum
Test(lib/win/net): Skip UDS tests when under Win7

Unix Domain Socket support has only been added to Windows since Windows 10 Insider Preview Build 17063. Thus, it has no chance of ever being supported under Windows 7, making current tests fail. This therefore adds the necessary in order to make the tests dynamically skip when run under Windows 7, 8, and early 10, as it does not trigger linker errors.

cc rust-lang/rust#150487 @roblabla

@rustbot label T-libs A-io O-windows-7
2026-02-14 23:17:32 -05:00
Paul Mabileau c22301b099 Test(lib/win/net): Skip UDS tests when under Win7
Unix Domain Socket support has only been added to Windows since Windows
10 Insider Preview Build 17063. Thus, it has no chance of ever being
supported under Windows 7, making current tests fail. This therefore
adds the necessary in order to make the tests dynamically skip when run
under Windows 7, 8, and early 10, as it does not trigger linker errors.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2026-02-14 01:28:50 +01:00
mu001999 73c42c1800 Remove or allow unused features in library doc and tests 2026-02-13 09:27:16 +08:00
Zalathar 6970849fee Disable flaky test oneshot::recv_timeout_before_send 2026-02-05 12:38:23 +11:00
Ralf Jung 079913ec71 disable socket tests in Miri 2026-02-03 09:02:39 +01:00
kouhe3 1689fcd1cc feat(windows): add Unix domain socket support
This commit introduces initial, unstable support for Unix domain sockets
(UDS) on Windows, behind the `windows_unix_domain_sockets` feature gate

Added types:
- `std::os::windows::net::SocketAddr`: represents a UDS address with support
  for pathname addresses (abstract and unnamed are parsed but not yet fully
  supported).
- `std::os::windows::net::UnixListener`: server-side UDS listener.
- `std::os::windows::net::UnixStream`: client/server stream for UDS.

Key features:
- Binding and connecting using filesystem paths.
- Basic I/O via `Read`/`Write`.
- Address querying (`local_addr`, `peer_addr`).
- Non-blocking mode, timeouts, and socket duplication.
- Includes basic test coverage for smoke, echo, path length, and bind reuse.
2026-01-31 18:36:49 +08:00
Stuart Cook 956ebbde20 Rollup merge of #151383 - cyrgani:no-internal-deprecation, r=scottmcm
remove `#[deprecated]` from unstable & internal `SipHasher13` and `24` types

These types are unstable and `doc(hidden)` (under the internal feature `hashmap_internals`). Deprecating them only adds noise (`#[allow(deprecated)]`) to all places where they are used, so this PR removes the deprecation attributes from them.

It also includes a few other small cleanups in separate commits, including one I overlooked in rust-lang/rust#151228.
2026-01-27 12:50:52 +11:00
Trevor Gross 490b307740 cleanup: Start splitting FIXME(f16_f128) into f16, f128, or f16,f128
Make it easier to identify which FIXMEs are blocking stabilization of
which type.
2026-01-22 23:41:57 -06:00
Trevor Gross 8840409f7a f16,f128: Resolve cfg-releated instances of FIXME(f16_f128)
There are a number of instances of `FIXME(f16_f128)` related to target
configuration; either these could use `target_has_reliable_f128`, or the
FIXME is describing such a cfg and is thus redundant (since any
`cfg(target_has_reliable_f*)` needs to be removed before stabilization
anyway).

Switch to using `target_has_reliable_*` where applicable and remove the
redundant FIXMEs.
2026-01-22 23:41:57 -06:00
cyrgani a175d05e85 remove old #[allow(deprecated)] for env::home_dir calls 2026-01-19 21:25:32 +00:00
Clara Engler 567b569e2b time: Add saturating arithmetic for SystemTime
This commit implements the following methods:
* `SystemTime::saturating_add`
* `SystemTime::saturating_sub`
* `SystemTime::saturating_duration_since`

The implementation of these methods is rather trivial, as the main logic
lies behind the constants `SystemTime::MIN` and `SystemTime::MAX`.
2026-01-16 11:52:01 +01:00
Connor Tsui b481ecd8b5 add oneshot tests
Tests inspired by tests in the `oneshot` third-party crate.
2026-01-05 09:47:20 +11:00
usamoi 141342c34f stabilize lazy_get 2025-12-15 18:57:33 +08:00
Clara Engler 1b9b4f4dc6 time: Test and document time precision edge-case
There is a slight edge case when adding and subtracting a `Duration`
from a `SystemTime`, namely when the duration itself is finer/smaller
than the time precision on the operating systems.

On most (if not all non-Windows) operating systems, the precision of
`Duration` aligns with the `SystemTime`, both being one nanosecond.

However, on Windows, this time precision is 100ns, meaning that adding
or subtracting a `Duration` whose value is `< Duration::new(0, 100)`
will result in that method behaving like an addition/subtracting of
`Duration::ZERO`, due to the `Duration` getting rounded-down to the zero
value.
2025-12-13 10:44:48 +01:00
Clara Engler ac5c70ad4d time: Implement SystemTime::{MIN, MAX}
This commit introduces two new constants to SystemTime: `MIN` and `MAX`,
whose value represent the maximum values for the respective data type,
depending upon the platform.

Technically, this value is already obtainable during runtime with the
following algorithm: Use `SystemTime::UNIX_EPOCH` and call `checked_add`
(or `checked_sub`) repeatedly with `Duration::new(0, 1)` on it, until it
returns None.  Mathematically speaking, this algorithm will terminate
after a finite amount of steps, yet it is impractical to run it, as it
takes practically forever.

Besides, this commit also adds a unit test.  Concrete implementation
depending upon the platform is done in later commits.

In the future, the hope of the authors lies within the creation of a
`SystemTime::saturating_add` and `SystemTime::saturating_sub`, similar
to the functions already present in `std::time::Duration`.  However, for
those, these constants are crucially required, thereby this should be
seen as the initial step towards this direction.

Below are platform specifc notes:

# Hermit

The HermitOS implementation is more or less identitcal to the Unix one.

# sgx

The implementation uses a `Duration` to store the Unix time, thereby
implying `Duration::ZERO` and `Duration::MAX` as the limits.

# solid

The implementation uses a `time_t` to store the system time within a
single value (i.e. no dual secs/nanosecs handling), thereby implying its
`::MIN` and `::MAX` values as the respective boundaries.

# UEFI

UEFI has a weird way to store times, i.e. a very complicated struct.
The standard proclaims "1900-01-01T00:00:00+0000" to be the lowest
possible value and `MAX_UEFI_TIME` is already present for the upper
limit.

# Windows

Windows is weird.  The Win32 documentation makes no statement on a
maximum value here.  Next to this, there are two conflicting types:
`SYSTEMTIME` and `FILETIME`.  Rust's Standard Library uses `FILETIME`,
whose limit will (probably) be `i64::MAX` packed into two integers.
However, `SYSTEMTIME` has a lower-limit.

# xous

It is similar to sgx in the sense of using a `Duration`.

# unsupported

Unsupported platforms store a `SystemTime` in a `Duration`, just like
sgx, thereby implying `Duration::ZERO` and `Duration::MAX` as the
respective limits.
2025-12-12 12:25:30 +01:00
bendn d67f99af2e fix 2025-11-27 17:55:34 +07:00
Matthew Maurer 17230eb5bb rustc_target: aarch64: Remove deprecated FEAT_TME
ARM has withdrawn FEAT_TME

https://developer.arm.com/documentation/102105/lb-05/

LLVM has dropped support for it recently as a result.
2025-11-25 00:43:01 +00:00
Folkert de Vries 776405c058 add missing s390x target feature to std detect test 2025-11-13 12:46:34 +01:00
Folkert de Vries c59298da36 stabilize stdarch_s390x_feature_detection 2025-11-06 12:49:46 +01:00
Connor Tsui c1153b08ff move condvar test from mutex to condvar test file
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-31 15:53:39 -04:00
Connor Tsui 3d5a40809c update nonpoison::Condvar to take guards by reference
Since non-poisoning `Condvar` take non-poisoing `Mutex`es when
`wait`ing, we do not need to take by ownership since a poison error
cannot occur while we wait.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-31 15:53:33 -04:00
Connor Tsui 7069400c47 revert combined nonpoison/poison tests for condvar
Setup for writing different tests for the `nonpoison::Condvar` since it
will have a different API.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-31 15:31:53 -04:00
Josh Stone a81ed52f58 Add a regression test for rust-lang/rust#147971 2025-10-23 12:37:53 -07: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
joboet 76dfdd4e70 handle spurious returns of wait_timeout in test 2025-10-20 17:53:49 +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
joboet 8a145efc70 std: improve handling of timed condition variable waits on macOS 2025-10-14 11:57:50 +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
Matthias Krüger 92aac1bdf6 Rollup merge of #146281 - Jules-Bertholet:static-align-thread-local, r=Mark-Simulacrum
Support `#[rustc_align_static]` inside `thread_local!`

Tracking issue: rust-lang/rust#146177

```rust
thread_local! {
    #[rustc_align_static(64)]
    static SO_ALIGNED: u64 = const { 0 };
}
```

This increases the amount of recursion the macro performs (once per attribute in addition to the previous once per item), making it easier to hit the recursion limit. I’ve added workarounds to limit the impact in the case of long doc comments, but this still needs a crater run just in case.

r? libs

``@rustbot`` label A-attributes A-macros A-thread-locals F-static_align T-libs
2025-10-02 10:27:48 +02:00
Matthias Krüger 61b9467af8 Rollup merge of #142506 - clarfonthey:path-trailing-sep, r=joboet
Add `Path::has_trailing_sep` and related methods

Implements rust-lang/libs-team#335.

Tracking issue: rust-lang/rust#142503

Notable differences from ACP:

* `trim_trailing_sep` was added to `Path` since it felt reasonable to ensure that the inverse operation was available.
* Per suggestion of `@kennytm,` added `push_trailing_sep` and `pop_trailing_sep` to `PathBuf` in addition to `set_trailing_sep`.

This also updates some of the docs on various `Path` methods to use the term "trailing separator" instead of "trailing slash" for consistency.
2025-09-30 20:46:44 +02:00
Jules Bertholet a4e87e9406 Support #[rustc_align_static] inside thread_local! 2025-09-26 13:51:09 -04:00
Matthias Krüger d10d6bfb02 Rollup merge of #146958 - el-ev:fix_path_string_eq_recurse, r=joboet
Fix infinite recursion in Path::eq with String

- Closes [after beta backport] rust-lang/rust#146940
2025-09-24 23:33:28 +02:00
Stepan Koltsov 92859e98ee Repro duration_since regression from issue 146228 2025-09-24 21:07:26 +01:00
Iris Shi 5a4e536036 Fix infinite recursion in Path::eq with String 2025-09-24 21:30:41 +08:00
Mads Marquart 37be93497e Fix test suite in iOS/tvOS/watchOS/visionOS simulator 2025-09-19 13:55:03 +02: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
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 https://github.com/rust-lang/rust/commit/e95db591a4550e28ad92660b753ad85b89271882
2025-09-10 20:29:07 +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 https://github.com/rust-lang/rust/commit/e95db591a4550e28ad92660b753ad85b89271882
2025-09-09 17:13:38 +02:00