Commit Graph

7993 Commits

Author SHA1 Message Date
Matthias Krüger
3237d4dc14 Rollup merge of #140984 - mlowicki:patch-2, r=ibraheemdev
fix doc for UnixStream

Doc example was using `UdpSocket` instead of `UnixStream`.
2025-05-16 07:19:40 +02:00
Matthias Krüger
370cd22e47 Rollup merge of #140910 - paolobarbolini:wasi-fs-incorrect-stabilization, r=joboet
Remove `stable` attribute from wasi fs (read_exact|write_all)_at

The docs for [`std::os::wasi::fs::FileExt::read_exact_at`](https://doc.rust-lang.org/1.86.0/std/os/wasi/fs/trait.FileExt.html#method.read_exact_at) and [`std::os::wasi::fs::FileExt::write_all_at`](https://doc.rust-lang.org/1.86.0/std/os/wasi/fs/trait.FileExt.html#method.write_all_at) show the methods to be stable since v1.33, which is not correct and was a mistake made when the methods were added in (https://github.com/rust-lang/rust/pull/74076#pullrequestreview-443124667). The reviewer seemed to think this was an insta-stabilization, but the entire file is marked as unstable so that was not right. The stabilization version would also have been wrong either way.
2025-05-16 07:19:39 +02:00
joboet
6647cbb515 improve internal fastfail explainer 2025-05-15 11:20:13 +02:00
joboet
b7f2cd3a2b deduplicate abort implementations
Currently, the code for process aborts is duplicated across `panic_abort` and `std`. This PR uses `#[rustc_std_internal_symbol]` to make the `std` implementation available to `panic_abort` via the linker, thereby deduplicating the code.
2025-05-15 11:20:13 +02:00
Eric Huss
57af157ce2 Update std doctests for android
This updates some doctests that fail to run on android. We will soon be
supporting cross-compiled doctests, and the `arm-android` job fails to
run these tests.

In summary:
- Android re-exports some traits from linux under a different path.
- Android doesn't seem to have common unix utilities like `true`,
  `false`, or `whoami`, so these are disabled.
2025-05-14 18:26:06 -07:00
teor
8f0522dc81 Fix confusing WTF surrogate safety docs 2025-05-15 07:58:30 +10:00
Federico Terzi
e0b6363974 wire up startupinfo methods 2025-05-14 19:00:56 +02: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
B I Mohammed Abbas
544c8ce535 Fix settimes for vxworks 2025-05-14 13:52:31 +05:30
B I Mohammed Abbas
e1f1878da5 Fix set_name for vxworks. Length of name should be truncated to VX_TASK_RENAME_LENGTH-1 2025-05-14 13:52:31 +05:30
Michał Łowicki
b9f4350fbc fix doc for UnixStream 2025-05-13 22:00:56 -04: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
Trevor Gross
36790d2881 Initial implementation of core_float_math
Since [1], `compiler-builtins` makes a certain set of math symbols
weakly available on all platforms. This means we can begin exposing some
of the related functions in `core`, so begin this process here.

It is not possible to provide inherent methods in both `core` and `std`
while giving them different stability gates, so standalone functions are
added instead. This provides a way to experiment with the functionality
while unstable; once it is time to stabilize, they can be converted to
inherent.

For `f16` and `f128`, everything is unstable so we can move the inherent
methods.

The following are included to start:

* floor
* ceil
* round
* round_ties_even
* trunc
* fract
* mul_add
* div_euclid
* rem_euclid
* powi
* sqrt
* abs_sub
* cbrt

These mirror the set of functions that we have in `compiler-builtins`
since [1].

Tracking issue: https://github.com/rust-lang/rust/issues/137578

[1]: https://github.com/rust-lang/compiler-builtins/pull/763
2025-05-13 22:08:18 +00:00
Pietro Albini
ce6e29679c bump compiler_builtins 2025-05-13 11:30:36 +02:00
Pietro Albini
2ce08ca5d6 update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
Pietro Albini
a360940ac9 update version placeholders 2025-05-12 15:33:30 +02:00
Paolo Barbolini
aeea4727a4 Remove stable attribute from wasi fs (read_exact|write_all)_at 2025-05-10 23:55:51 +00:00
Matthias Krüger
8186b71fb4 Rollup merge of #140783 - veluca93:oncelock-docs, r=jhpratt
Update documentation of OnceLock::get_or_init.

Explicitly point out that if the function panics the init function might be called multiple times.
2025-05-10 16:26:03 +02:00
Matthias Krüger
c6b9253ad5 Rollup merge of #129334 - ChayimFriedman2:more-lazy-methods, r=Amanieu
Implement (part of) ACP 429: add `DerefMut` to `Lazy[Cell/Lock]`

`DerefMut` is instantly stable, as a trait impl. That means this needs an FCP.

``@rustbot`` label +needs-fcp

https://github.com/rust-lang/libs-team/issues/429
2025-05-10 16:26:01 +02:00
Matthias Krüger
7fc43e50c7 Rollup merge of #140759 - dpaoliello:symlink, r=workingjubilee
[win][arm64] Disable std::fs tests that require symlinks

While trying to get the aarch64-msvc build working correctly (#140136), various tests in `std::fs` were failing as the Arm64 Windows runner image we are using does not have Developer Mode enabled, thus it cannot create symlinks.

I've [filed a request to get Developer Mode enabled](https://github.com/actions/partner-runner-images/issues/94), but in the meantime I've disabled the relevant tests on Arm64 Windows.
2025-05-08 13:55:46 +02:00
Luca Versari
ae25c39f22 Update documentation of OnceLock::get_or_init.
Explicitly point out that if the function panics the init function might
be called multiple times.
2025-05-08 09:33:38 +02:00
Daniel Paoliello
0cacc05531 [win][arm64] Disable FS tests that require symlinks 2025-05-07 11:12:11 -07:00
Guillaume Gomez
5152ab2f5e Rollup merge of #140734 - ivmarkov:master, r=joboet
Fix regression from #140393 for espidf / horizon / nuttx / vita

#140393 introduced changes to the layout of the `std::sys::process` code.
As a result, the Tier 3 ESP-IDF (and I suspect Horizon, Nuttx and Vita targets as well) no longer build.

A `pub use unsupported::output` is all that was missing - for the above OSes specifically. This explicit `pub use` is now necessary, because #140393 moved the `output` function to module-level, where it was previously part of `Command` and was thus re-exported automatically, as part of the `imp::Command` re-export further down the file containing the one-liner fix.

Note that - with the change introduced by #140393 - we **can't** anymore just do an unconditional `pub use imp::output` as this function simply does not exist anymore anywhere else but in the `unsupported` module.

r? `@joboet`
2025-05-07 18:19:08 +02:00
Guillaume Gomez
aca12a8216 Rollup merge of #140724 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.158

Includes the following changes:

* Require `target_has_atomic = "ptr"` for runtime feature detection [1]

[1]: https://github.com/rust-lang/compiler-builtins/pull/909
2025-05-07 10:50:50 +02:00
Guillaume Gomez
6e2c39b568 Rollup merge of #140398 - Berrysoft:cygwin-backtrace, r=tgross35
Fix backtrace for cygwin

Closes #140304

Depends on:
- [x] https://github.com/rust-lang/backtrace-rs/pull/704

This PR could not be merged until the above PR is merged. I'll update the submodule then.

EDIT: submodule updated.
2025-05-07 10:50:49 +02:00
ivmarkov
392880c004 Fix regression from #140393 for espidf / horizon / nuttx / vita 2025-05-07 08:04:21 +00:00
王宇逸
fe64184b16 Fix backtrace for cygwin 2025-05-07 13:08:19 +08:00
Jacob Pratt
fe97fe45f8 Rollup merge of #140656 - joboet:fuchsia_pal, r=workingjubilee
collect all Fuchsia bindings into the `fuchsia` module

The Fuchsia bindings are currently spread out across multiple modules in `sys/pal/unix` leading to unnecessary duplication. This PR moves all of these definitions into `sys::pal::unix::fuchsia` and additionally:
* deduplicates the definitions
* makes the error names consistent
* marks `zx_thread_self` and `zx_clock_get_monotonic` as safe extern functions
* removes unused items (there's no need to maintain these bindings if we're not going to use them)
* removes the documentation for the definitions (contributors should always consult the platform documentation, duplicating that here is just an extra maintenance burden)

`@rustbot` ping fuchsia
2025-05-07 00:29:24 +00:00
Trevor Gross
4de822c3d2 Update compiler-builtins to 0.1.158
Includes the following changes:

* Require `target_has_atomic = "ptr"` for runtime feature detection

[1]: https://github.com/rust-lang/compiler-builtins/pull/909
2025-05-06 23:40:50 +00:00
Stuart Cook
7cd7605277 Rollup merge of #140393 - joboet:sys_common_process, r=thomcc
std: get rid of `sys_common::process`

Move the public `CommandEnvs` into the `process` module (and make it a wrapper type for an internal iterator type) and everything else into `sys::process` as per #117276.

Something went wrong with a force push, so I can't reopen #139020. This is unchanged from that PR, apart from a rebase.

r? ```@thomcc```
2025-05-06 16:28:40 +10:00
Stuart Cook
d5c09b4aa6 Rollup merge of #139773 - thaliaarchi:vec-into-iter-last, r=workingjubilee
Implement `Iterator::last` for `vec::IntoIter`

Avoid iterating everything when we have random access to the last element.
2025-05-06 16:28:39 +10:00
Stuart Cook
5ca0053c79 Rollup merge of #139764 - dtolnay:extractif, r=Amanieu
Consistent trait bounds for ExtractIf Debug impls

Closes #137654. Refer to that issue for a table of the **4** different impl signatures we previously had in the standard library for Debug impls of various ExtractIf iterator types.

The one we are standardizing on is the one so far only used by `alloc::collections::linked_list::ExtractIf`, which is _no_ `F: Debug` bound, _no_ `F: FnMut` bound, only `T: Debug` bound.

This PR applies the following signature changes:

```diff
/* alloc::collections::btree_map */

    pub struct ExtractIf<'a, K, V, F, A = Global>
    where
-       F: 'a + FnMut(&K, &mut V) -> bool,
        Allocator + Clone,

    impl Debug for ExtractIf<'a, K, V, F,
+       A,
    >
    where
        K: Debug,
        V: Debug,
-       F: FnMut(&K, &mut V) -> bool,
+       A: Allocator + Clone,
```

```diff
/* alloc::collections::btree_set */

    pub struct ExtractIf<'a, T, F, A = Global>
    where
-       T: 'a,
-       F: 'a + FnMut(&T) -> bool,
        Allocator + Clone,

    impl Debug for ExtractIf<'a, T, F, A>
    where
        T: Debug,
-       F: FnMut(&T) -> bool,
        A: Allocator + Clone,
```

```diff
/* alloc::collections::linked_list */

    impl Debug for ExtractIf<'a, T, F,
+       A,
    >
    where
        T: Debug,
+       A: Allocator,
```

```diff
/* alloc::vec */

    impl Debug for ExtractIf<'a, T, F, A>
    where
        T: Debug,
-       F: Debug,
        A: Allocator,
-       A: Debug,
```

```diff
/* std::collections::hash_map */

    pub struct ExtractIf<'a, K, V, F>
    where
-       F: FnMut(&K, &mut V) -> bool,

    impl Debug for ExtractIf<'a, K, V, F>
    where
+       K: Debug,
+       V: Debug,
-       F: FnMut(&K, &mut V) -> bool,
```

```diff
/* std::collections::hash_set */

    pub struct ExtractIf<'a, T, F>
    where
-       F: FnMut(&T) -> bool,

    impl Debug for ExtractIf<'a, T, F>
    where
+       T: Debug,
-       F: FnMut(&T) -> bool,
```

I have made the following changes to bring these types into better alignment with one another.

- Delete `F: Debug` bounds. These are especially problematic because Rust closures do not come with a Debug impl, rendering the impl useless.

- Delete `A: Debug` bounds. Allocator parameters are unstable for now, but in the future this would become an API commitment that we do not debug-print a representation of the allocator when printing an iterator.

- Delete `F: FnMut` bounds. Requires `hashbrown` PR: https://github.com/rust-lang/hashbrown/pull/616. **API commitment:** we commit to not doing RefCell voodoo inside ExtractIf to have some way for its Debug impl (which takes &amp;self) to call a FnMut closure, if this is even possible.

- Add `T: Debug` bounds (or `K`/`V`), even on Debug impls that do not currently make use of them, but might in the future. **Breaking change.** Must backport into Rust 1.87 (current beta) or do a de-stabilization PR in beta to delay those types by one release.

- Render using `debug_struct` + `finish_non_exhaustive`, instead of `debug_tuple`.

- Do not render the _entire_ underlying collection.

- Show a "peek" field indicating the current position of the iterator.
2025-05-06 16:28:38 +10:00
David Tolnay
c35914383a Consistent trait bounds for ExtractIf Debug impls 2025-05-05 19:46:46 -07:00
joboet
84bb0f07e6 std: stop using TLS in signal handler
TLS is not async-signal-safe, making its use in the signal handler used to detect stack overflows unsound (c.f. #133698). POSIX however lists two thread-specific identifiers that can be obtained in a signal handler: the current `pthread_t` and the address of `errno`. Since `pthread_equal` is not AS-safe, `pthread_t` should be considered opaque, so for our purposes, `&errno` is the only option. This however works nicely: we can use the address as a key into a map that stores information for each thread. This PR uses a `BTreeMap` protected by a spin lock to hold the guard page address and thread name and thus fixes #133698.
2025-05-05 15:18:52 +02:00
joboet
7845c011dd collect all Fuchsia bindings into the fuchsia module
The Fuchsia bindings are currently spread out across multiple modules in `sys/pal/unix` leading to unnecessary duplication. This PR moves all of these definitions into `sys::pal::unix::fuchsia` and additionally:
* deduplicates the definitions
* makes the error names consistent
* marks some extern functions as safe
* removes unused items (there's no need to maintain these bindings if we're not going to use them)
* removes the documentation for the definitions (contributors should always consult the platform documentation, duplicating that here is just an extra maintenance burden)
2025-05-05 12:16:40 +02:00
Trevor Gross
435fc7d685 Update compiler-builtins to 0.1.157
Includes the following changes:

* Use runtime feature detection for fma routines on x86 [1]

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

[1]: https://github.com/rust-lang/compiler-builtins/pull/896
2025-05-04 22:54:55 +00:00
Matthias Krüger
2820bdb740 Rollup merge of #140595 - lolbinarycat:std-set_permissions-typo, r=cuviper
doc(std): fix typo lchown -> lchmod

chown is irrelevant here, as this function does not affect file ownership.  chmod is the correct function to reference here.
2025-05-03 12:44:36 +02:00
Matthias Krüger
422dfe6772 Rollup merge of #140564 - ebkalderon:use-present-indicative-in-std-io-pipe-docs, r=tgross35
Use present indicative tense in std::io::pipe() API docs

The inline documentation for all other free functions in the `std::io` module use the phrase "creates a" instead of "create a", except for the currently nightly-only `std::io::pipe()` function. This commit updates the text to align with the predominant wording in the `std::io` module.

I recognize this PR is quite a minuscule nitpick, so feel free to ignore and close if you disagree and/or there are bigger fish to fry. Thanks in advance! 😄

Relates to https://github.com/rust-lang/rust/issues/127154.
2025-05-03 08:45:04 +02:00
Matthias Krüger
69e0844a46 Rollup merge of #139343 - cberner:filelock_wouldblock, r=workingjubilee
Change signature of File::try_lock and File::try_lock_shared

These methods now return Result<(), TryLockError> instead of Result<bool, Error> to make their use less errorprone

These methods are unstable under the "file_lock" feature. The related tracking issue is https://github.com/rust-lang/rust/pull/130999 and this PR changes the signatures as discussed by libs-api: https://github.com/rust-lang/rust/issues/130994#issuecomment-2770838848
2025-05-03 08:45:01 +02:00
Thalia Archibald
cbdd7134ff Implement Iterator::last for vec::IntoIter 2025-05-02 20:08:28 -07:00
Matthias Krüger
06599db9c1 Rollup merge of #140536 - zachs18:mapped-guard-filter-map, r=Amanieu
Rename `*Guard::try_map` to `filter_map`.

Rename `std::sync::*Guard::try_map` to `filter_map`.

1. Analogous to `std::cell::Ref(Mut)::filter_map`.
2. Doesn't imply `Try` genericizability.

r? `@Amanieu` (or other T-libs-api)

Tracking issue for `mapped_lock_guards`: https://github.com/rust-lang/rust/issues/117108
2025-05-02 19:37:58 +02:00
binarycat
b7c933a495 doc(std): fix typo lchown -> lchmod 2025-05-02 12:13:40 -05:00
Stuart Cook
27d419a6b5 Rollup merge of #140389 - sayantn:avx512fp16, r=Amanieu
Remove `avx512dq` and `avx512vl` implication for `avx512fp16`

According to Intel, `avx512fp16` requires only `avx512bw`, but LLVM also enables `avx512vl` and `avx512dq` when `avx512fp16` is active. This is relic code, and will be fixed in LLVM soon. We should remove this from Rust too asap, especially before the stabilization of AVX512

Related:
 - llvm/llvm-project#136209
 - #138940
 - rust-lang/stdarch#1781
 - #111137

``@rustbot`` label O-x86_64 O-x86_32 A-SIMD A-target-feature T-compiler -T-libs
r? ``@Amanieu``

**Update: the LLVM fix has been merged**

cc ``@rust-lang/wg-llvm`` will it be possible to update the rustc llvm version to something after llvm/llvm-project#137450
2025-05-02 22:17:02 +10:00
Stuart Cook
30e556e772 Rollup merge of #140197 - ktnlvr:master, r=workingjubilee
Document breaking out of a named code block

Closes #110758.
2025-05-02 22:17:01 +10:00
Stuart Cook
5a58c7a6ab Rollup merge of #140159 - thaliaarchi:pathbuf-extension, r=workingjubilee
Avoid redundant WTF-8 checks in `PathBuf`

Eliminate checks for WTF-8 boundaries in `PathBuf::set_extension` and `add_extension`, where joining WTF-8 surrogate halves is impossible. Don't convert the `str` to `OsStr`, because `OsString::push` specializes to skip the joining when given strings.

To assist in this, mark the internal methods `OsString::truncate` and `extend_from_slice` as `unsafe` to communicate their safety invariants better than with module privacy.

Similar to #137777.

cc `@joboet` `@ChrisDenton`
2025-05-02 22:17:00 +10:00
Stuart Cook
6fc78d410d Rollup merge of #139847 - thaliaarchi:args/delegate-iter, r=workingjubilee
Delegate to inner `vec::IntoIter` from `env::ArgsOs`

Delegate from `std::env::ArgsOs` to the methods of the inner platform-specific iterators, when it would be more efficient than just using the default methods of its own impl. Most platforms use `vec::IntoIter` as the inner type, so prioritize delegating to the methods it provides.

`std::env::Args` is implemented atop `std::env::ArgsOs` and performs UTF-8 validation with a panic for invalid data. This is a visible effect which users certainly rely on, so we can't skip any arguments. Any further iterator methods would skip some elements, so no change is needed for that type.

Add `#[inline]` for any methods which simply wrap the inner iterator.
2025-05-02 22:17:00 +10:00
Stuart Cook
192fbcc83a Rollup merge of #139608 - Lynnesbian:improve-async-block-docs, r=ibraheemdev
Clarify `async` block behaviour

Adds some documentation for control flow behaviour pertaining to `return` and `?` within `async` blocks. Fixes (or at least improves) #101444.

r? rust-lang/docs
2025-05-02 22:16:59 +10:00
Stuart Cook
8ffdb00d44 Rollup merge of #139206 - joboet:unique_thread_errno, r=ibraheemdev
std: use the address of `errno` to identify threads in `unique_thread_exit`

Getting the address of `errno` should be just as cheap as `pthread_self()` and avoids having to use the expensive `Mutex` logic because it always results in a pointer.
2025-05-02 22:16:59 +10:00
Christopher Berner
1d11ee2a5b Implement error::Error for TryLockError 2025-05-01 20:39:05 -07:00
Christopher Berner
042a556d8d Change signature of File::try_lock and File::try_lock_shared
These methods now return Result<(), TryLockError> instead of
Result<bool, Error> to make their use less errorprone
2025-05-01 20:39:05 -07:00