Commit Graph

8027 Commits

Author SHA1 Message Date
Josh Triplett
348c1b0d88 Apply suggestions from code review
Link `Command::current_dir`.

Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2025-05-21 07:48:46 +02:00
Trevor Gross
999967a57d Rename cfg_match! to cfg_select!
At [1] it was pointed out that `cfg_match!` syntax does not actually
align well with match syntax, which is a possible source of confusion.
The comment points out that usage is instead more similar to ecosystem
`select!` macros. Rename `cfg_match!` to `cfg_select!` to match this.

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

[1]: https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605
2025-05-20 21:16:23 +00:00
Christopher Berner
fd260d530b Add From<TryLockError> for io::Error
This makes error propagation from try_lock() and try_lock_shared()
more convenient
2025-05-20 14:09:27 -07:00
Christopher Berner
9febbf8270 Remove unnecessary handling of ERROR_IO_PENDING
try_lock() and try_lock_shared() do not need to handle these per the discussion in https://github.com/rust-lang/rust/pull/140718#discussion_r2076678485
2025-05-20 14:09:27 -07:00
Matthias Krüger
c052d263d0 Rollup merge of #141289 - compiler-errors:more-self, r=jhpratt
use `Self` alias in self types rather than manually substituting it

Of the rougly 145 uses of `self: Ty` in the standard library, 5 of them don't use `Self` but instead choose to manually "substitute" the `impl`'s self type into the type.

This leads to weird behavior sometimes (https://github.com/rust-lang/rust/issues/140611#issuecomment-2883761300) -- **to be clear**, none of these usages actually trigger any bugs, but it's possible that they may break in the future (or at least lead to lints), so let's just "fix" them proactively.
2025-05-20 20:57:28 +02:00
Josh Triplett
17fdf19c9c CommandExt::chroot: Add tracking issue 2025-05-20 18:25:06 +02:00
Josh Triplett
c3b750ce0f CommandExt::chroot: Document difference to underlying chroot 2025-05-20 18:25:06 +02:00
Josh Triplett
a3cf6f6408 Add std::os::unix::process::CommandExt::chroot to safely chroot a child process
This adds a `chroot` method to the `CommandExt` extension trait for the
`Command` builder, to set a directory to chroot into. This will chroot
the child process into that directory right before calling chdir for the
`Command`'s working directory.

To avoid allowing a process to have a working directory outside of the
chroot, if the `Command` does not yet have a working directory set,
`chroot` will set its working directory to "/".
2025-05-20 18:25:05 +02:00
Daniel McNab
f6709bb683 core_float_math: Move functions to math folder
When these functions were added in
https://github.com/rust-lang/rust/pull/138087
It made a relatively common pattern for emulating
these functions using an extension trait (which
internally uses `libm`) much more fragile.
If `core::f32` happened to be imported by the user
(to access a constant, say), then that import in
the module namespace would take precedence over
`f32` in the type namespace for resolving these
functions, running headfirst into the stability
attribute.

We ran into this in Color -
https://github.com/linebender/color - and chose to
release the remedial 0.3.1 and 0.2.4, to allow
downstream crates to build on `docs.rs`.
As these methods are perma-unstable, moving them
into a new module should not have any long-term
concerns, and ensures that this breakage doesn't
adversely impact anyone else.
2025-05-20 16:41:43 +01:00
Michael Goulet
7b5ea0e7f5 use Self alias in self types rather than manually substituting it 2025-05-20 16:03:04 +02:00
Stuart Cook
66388d9892 Rollup merge of #141211 - fluiderson:dev, r=thomcc
Replace `try_reserve_exact` with `try_with_capacity` in `std::fs::read`

This change restores the previous behavior prior to #117925. That PR was made to handle OOM errors that turn into a panic with `Vec::with_capacity`. `try_reserve_exact` was used for that since there was no `try_with_capacity` method at the time. It was added later in #120504. I think it'd a better fit here.
2025-05-20 12:53:13 +10:00
bors
60dabef95a Auto merge of #138023 - melrief:97227_impl_Seek_for_Take, r=tgross35
Add `std::io::Seek` instance for `std::io::Take`

Library tracking issue [#97227](https://github.com/rust-lang/rust/issues/97227).
ACP: https://github.com/rust-lang/libs-team/issues/555

1. add a `len` field to `Take` to keep track of the original number of bytes that `Take` could read
2. add a `position()` method to return the current position of the cursor inside `Take`
3. implement `std::io::Seek` for `std::io::Take`

Closes: https://github.com/rust-lang/libs-team/issues/555
2025-05-19 19:28:16 +00:00
Matthias Krüger
6e784f842a Rollup merge of #141248 - RalfJung:reentrant-lock-race, r=joboet
fix data race in ReentrantLock fallback for targets without 64bit atomics

See [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/269128-miri/topic/reentrant.20lock.20failure.20on.20musl) for details: the address used to identify a thread might get lazily allocated inside `tls_addr()`, so if we call that *after* doing the `tls_addr.load()` it is too late to establish synchronization with prior threads that used the same address -- the `load()` thus races with the `store()` by that prior thread, and might hence see outdated values, and then the entire logic breaks down.

r? `@joboet`
2025-05-19 18:08:42 +02:00
Mario Pastorelli
c8f5ff867d Add std::io::Seek instance for std::io::Take 2025-05-19 17:56:46 +02:00
Ralf Jung
a14e25c768 windows: document that we rely on an undocumented property of GetUserProfileDirectoryW 2025-05-19 17:06:02 +02:00
Ralf Jung
8286487c0c fix data race in ReentrantLock fallback for targets without 64bit atomics 2025-05-19 15:21:25 +02:00
León Orell Valerian Liehr
6f415e0f4c Rollup merge of #140628 - joboet:async_signal_safe, r=Mark-Simulacrum
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-18 18:44:11 +02:00
León Orell Valerian Liehr
eb21b252c6 Rollup merge of #140966 - est31:let_chains_library, r=tgross35
Remove #![feature(let_chains)] from library and src/librustdoc

PR https://github.com/rust-lang/rust/pull/132833 has stabilized the `let_chains` feature. This PR removes the last occurences from the library, the compiler, and librustdoc (also because #140887 missed the conditional in one of the crates as it was behind the "rustc" feature).

We keep `core` as exercise for the future as updating it is non-trivial (see PR thread).
2025-05-18 11:03:45 +02:00
Fluid
0dec3fee34 replace try_reserve_exact with try_with_capacity in std::fs::read 2025-05-18 09:54:57 +03:00
bors
777d372772 Auto merge of #138087 - tgross35:core-float-math, r=Amanieu
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], with the exception of `powi` that has been there longer.

Details for each of the changes is in the commit messages.

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

[1]: https://github.com/rust-lang/compiler-builtins/pull/763

try-job: aarch64-gnu
tru-job: armhf-gnu
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
2025-05-17 19:31:39 +00: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
Matthias Krüger
b9839ab329 Rollup merge of #139103 - joboet:abort_dedup, r=tgross35
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-17 15:45:20 +02:00
mejrs
c9b6ccc11c Switch library rustc_unimplemented to use Self and This 2025-05-17 12:50:37 +02:00
GrantBirki
604f0e2743 remove test_embedded_null_byte() test for now 2025-05-16 22:42:05 -07:00
Jack O'Connor
dcef449e2c discuss deadlocks in the std::io::pipe() example 2025-05-16 20:59:45 -07:00
Paul Mabileau
a9330dd0e9 Docs(lib/coll/hm): Add kv pair to extract_if's first sentence
Make it consistent in this regard with `BTreeMap`'s.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17 02:49:57 +02:00
Paul Mabileau
014434e96f Docs(lib/extract_if): Unify paragraph about elements mutation
Take the one from `BTreeMap` that seems the best-worded and most
precise among the available variations.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17 02:45:56 +02:00
Paul Mabileau
9205ee27a8 Docs(lib/extract_if): Unify paragraph about closure actions
Also fixes `HashSet`'s that incorrectly designated itself as a `list`.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17 02:36:08 +02:00
Paul Mabileau
cd5772e396 Docs(lib/coll/hm): Reword extract_if to use element instead of value
A minor change, but it seemed interesting to unify this one's
description, especially considering all the other equivalents use
`element` as well.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17 02:14:55 +02:00
GrantBirki
49658e6a3c additional edge cases tests for path.rs 2025-05-16 15:19:44 -07:00
est31
258e880861 Remove #![feature(let_chains)] from library and src/librustdoc 2025-05-16 16:14:24 +02:00
joboet
2cdbd69abf disable the stack overflow handler on miri 2025-05-16 14:25:15 +02:00
Matthias Krüger
03912f40ef Rollup merge of #141013 - federico-terzi:feat/command_startupinfo_windows, r=joboet
Implement methods to set STARTUPINFO flags for Command API on Windows

Implements https://github.com/rust-lang/rust/issues/141010
2025-05-16 07:19:42 +02:00
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