19303 Commits

Author SHA1 Message Date
Jacob Pratt
c27b7c2214
Rollup merge of #141361 - folkertdev:varargs-cfg, r=workingjubilee
use `cfg_select!` to select the right `VaListImpl` definition

tracking issue: https://github.com/rust-lang/rust/issues/44930

Just a bit of cleanup really.

We could use `PhantomInvariantLifetime<'f>` (https://github.com/rust-lang/rust/issues/135806) to make it more precise what that `PhantomData<&'f mut &'f c_void>` marker is doing. I'm not sure how ready that feature is though, `@jhpratt` are these types good to use internally?

---

Some research into the lifetimes of `VaList` and `VaListImpl`:

It's easy to see why the lifetime of these types should not be extended, a `VaList` or `VaListImpl` escaping its function is a bad idea. I don't currently see why coercing the lifetime to a shorter lifetime is problematic though, but probably I just don't understand variance well enough to see it. The history does not provide much explanation:

- 08140878fe original implementation
- b9ea653aee adds `VaListImpl<'f>`, but it is only covariant in `'f`
- https://github.com/rust-lang/rust/pull/62639 makes `VaListImpl<'f>` invariant over `'f` (because `VaList<'a, 'f>` is already invariant over `'f`, but I think that is just an implementation detail?)

Beyond that I don't see how the lifetime situation can be simplified significantly, e.g. this function really needs `'copy` to be unconstrained.

```rust
/// Copies the `va_list` at the current location.
pub unsafe fn with_copy<F, R>(&self, f: F) -> R
where
    F: for<'copy> FnOnce(VaList<'copy, 'f>) -> R,
{
    let mut ap = self.clone();
    let ret = f(ap.as_va_list());
    // SAFETY: the caller must uphold the safety contract for `va_end`.
    unsafe {
        va_end(&mut ap);
    }
    ret
}
```

`@rustbot` label +F-c_variadic
r? `@workingjubilee`
2025-05-25 04:00:57 +02:00
Jacob Pratt
3338ff7dcf
Rollup merge of #141108 - PaulDance:fix-extract_if-docs, r=Mark-Simulacrum
Docs(lib): Fix `extract_if` docs

Various fixes to the documentation comments of the several `extract_if` collection methods available. It originally started with a small typo fix in `Vec`'s spotted when reading the 1.87 release notes, but then by looking at the others' for comparison in order to try determining what was the intended sentence, some inconsistencies were spotted. Therefore, some other changes are also proposed here to reduce these avoidable differences, going more and more nit-picky along the way. See the individual commits for more details about each change.

`@rustbot` label T-libs A-collections A-docs
2025-05-25 04:00:56 +02:00
Guillaume Gomez
76ca0e2d62
Rollup merge of #141505 - RalfJung:catch_unwind, r=Noratrieb
rename internal panicking::try to catch_unwind

The public function is called `catch_unwind`, the intrinsic at some point got renamed to `catch_unwind` -- there's no reason to have the internal implementation of this still be called `try`, so let's rename it to match the rest.
2025-05-24 21:23:49 +02:00
Guillaume Gomez
c4a313ad06
Rollup merge of #141498 - tamird:cstr-example-noise, r=jhpratt
Use C-string literals to reduce boilerplate

Reduce boilerplate in doctests by replacing fallible function calls with
literals.
2025-05-24 21:23:49 +02: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
Guillaume Gomez
07157b78b1
Rollup merge of #140066 - thaliaarchi:const-array-as-mut-slice, r=jhpratt
Stabilize `<[T; N]>::as_mut_slice` as `const`

This is trivial and has no design questions.

Tracked in https://github.com/rust-lang/rust/issues/133333.

r? libs-api
2025-05-24 21:23:47 +02:00
Ralf Jung
1827bc0f39 rename internal panicking::try to catch_unwind 2025-05-24 16:32:00 +02:00
Matthias Krüger
d29204071b
Rollup merge of #139254 - Ayush1325:uefi-tcp4-connect, r=joboet
std: sys: net: uefi: Implement TCP4 connect

- Implement TCP4 connect using EFI_TCP4_PROTOCOL.
- Tested on QEMU setup with connecting to TCP server on host.
2025-05-24 16:08:46 +02:00
Matthias Krüger
334d7bd698
Rollup merge of #137323 - joshlf:transmute-npo, r=RalfJung
Guarantee behavior of transmuting `Option::<T>::None` subject to NPO

In https://github.com/rust-lang/rust/pull/115333, we added a guarantee that transmuting from `[0u8; N]` to `Option<P>` is sound where `P` is a pointer type subject to the null pointer optimization (NPO). It would be useful to be able to guarantee the inverse - that a `None::<P>` value can be transmutes to an array and that will yield `[0u8; N]`.

Closes #117591
2025-05-24 16:08:45 +02:00
Tamir Duberstein
7b5a079368
Use C-string literals to reduce boilerplate
Reduce boilerplate in doctests by replacing fallible function calls with
literals.
2025-05-24 08:34:16 -04:00
bors
3de4f1ccf3 Auto merge of #141484 - matthiaskrgr:rollup-dc58owu, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #141405 (GetUserProfileDirectoryW is now documented to always store the size)
 - #141427 (Disable `triagebot`'s `glacier` handler)
 - #141429 (Dont walk into unsafe binders when emiting error for non-structural type match)
 - #141438 (Do not try to confirm non-dyn compatible method)
 - #141444 (Improve CONTRIBUTING.md grammar and clarity)
 - #141446 (Add 2nd Solaris target maintainer)
 - #141456 (Suggest correct `version("..")` predicate syntax in check-cfg)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-24 10:00:14 +00:00
Matthias Krüger
48c4a46c8e
Rollup merge of #141405 - RalfJung:GetUserProfileDirectoryW, r=ChrisDenton
GetUserProfileDirectoryW is now documented to always store the size

Update to match https://github.com/MicrosoftDocs/sdk-api/pull/1810

Also fix a bug in the Miri implementation while I am starting at that code...

r? ```@ChrisDenton```
Fixes #141254
2025-05-24 09:23:39 +02:00
bors
5af801b687 Auto merge of #141415 - est31:let_chains_libcore, r=tgross35
Remove #![feature(let_chains)] from libcore

PR https://github.com/rust-lang/rust/pull/132833 has stabilized the let_chains feature. This PR removes the last occurrence from the library.

Split out of #140966 as it caused breakage. Now we have a patch to the linux tree that fixes the build, so we update the linux tree to it.

cc https://github.com/Rust-for-Linux/linux/issues/1163
cc https://github.com/rust-lang/rust/issues/140722
2025-05-24 06:49:47 +00:00
Ralf Jung
587653a2fc GetUserProfileDirectoryW is now documented to always store the size 2025-05-23 22:36:40 +02:00
Matthias Krüger
be2705caf2
Rollup merge of #141398 - Dannyyy93:typos, r=Noratrieb
chore: fix typos in comment

## Fix Typos in Comments

This PR addresses several typos in the Rust standard library's documentation comments:

- In `library/std/src/sync/mpmc/list.rs`: Corrected "attemped" to "attempted"
- In `library/std/src/sys/thread_local/guard/key.rs`: Fixed "defering" to "deferring"
- In `library/std/src/sys/thread_local/guard/key.rs`: Fixed "futher" to "further"

These changes improve documentation readability and consistency without affecting any functional code.
2025-05-23 20:30:11 +02:00
Matthias Krüger
672ad6e172
Rollup merge of #141065 - ehuss:wasm-doctest-xcompile, r=Mark-Simulacrum
Updated std doctests for wasm

This updates some doctests that fail to run on wasm. We will soon be supporting cross-compiled doctests, and the test-various job fails to run these tests. These tests fail because wasm32-wasip1 does not support threads.
2025-05-23 20:30:09 +02:00
Matthias Krüger
c66c8e6b9c
Rollup merge of #138896 - joboet:process_noalias, r=Noratrieb
std: fix aliasing bug in UNIX process implementation

`CStringArray` contained both `CString`s and their pointers. Unfortunately, since `CString` uses `Box`, moving the `CString`s into the `Vec` can (under stacked borrows) invalidate the pointer to the string, meaning the resulting `Vec<*const c_char>` was, from an opsem perspective, unusable. This PR removes removes the `Vec<CString>` from `CStringArray`, instead recreating the `CString`/`CStr` from the pointers when necessary. Also,`CStringArray` is now used for the process args as well, the old implementation was suffering from the same kind of bug.
2025-05-23 20:30:08 +02:00
Ayush Singh
e21aab5b5c
std: sys: net: uefi: Implement TCP4 connect
- Implement TCP4 connect using EFI_TCP4_PROTOCOL.
- Tested on QEMU setup with connecting to TCP server on host.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-05-23 23:49:33 +05:30
joboet
89a90d6640
std: add safety comments to CStringArray 2025-05-23 17:09:02 +02:00
joboet
a467516c22
std: fix aliasing bug in UNIX process implementation
`CStringArray` contained both `CString`s and their pointers. Unfortunately, since `CString` uses `Box`, moving the `CString`s into the `Vec` can (under stacked borrows) invalidate the pointer to the string, meaning the resulting `Vec<*const c_char>` was, from an opsem perspective, unusable. This PR removes removes the `Vec<CString>` from `CStringArray`, instead recreating the `CString`/`CStr` from the pointers when necessary. Also,`CStringArray` is now used for the process args as well, the old implementation was suffering from the same kind of bug.
2025-05-23 17:09:00 +02:00
Matthias Krüger
dfa3110ed4
Rollup merge of #141109 - oconnor663:pipe_example, r=Mark-Simulacrum
discuss deadlocks in the std::io::pipe() example

I think it's important to discuss deadlocks in examples of how to use pipes. The current example does include an explicit `drop()`, but it also implicitly relies on the fact that the `Command` object is temporary, so that it drops its copy of `pong_tx`. This sort of thing tends to trip people up when they use pipes for the first time. I might've gone overboard with the comments in this version, but I'm curious what folks think.
2025-05-23 13:34:19 +02:00
Matthias Krüger
036607ebba
Rollup merge of #141019 - ehuss:android-doctest-xcompile, r=Mark-Simulacrum
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-23 13:34:18 +02:00
Folkert de Vries
89a8abc4be
use cfg_select! to select the right VaListImpl definition 2025-05-23 12:51:04 +02:00
est31
6d71674321 Remove #![feature(let_chains)] from libcore 2025-05-23 02:47:43 +02:00
bors
912981a9ea Auto merge of #141396 - matthiaskrgr:rollup-feg050g, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #135562 (Add ignore value suggestion in closure body)
 - #139635 (Finalize repeat expr inference behaviour with inferred repeat counts)
 - #139668 (Handle regions equivalent to 'static in non_local_bounds)
 - #140218 (HIR ty lowering: Clean up & refactor the lowering of type-relative paths)
 - #140435 (use uX::from instead of _ as uX in non - const contexts)
 - #141130 (rustc_on_unimplemented cleanups)
 - #141286 (Querify `coroutine_hidden_types`)

Failed merges:

 - #140247 (Don't build `ParamEnv` and do trait solving in `ItemCtxt`s when lowering IATs)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-22 21:02:18 +00:00
Dannyyy93
d6dc08c3f4 docs: fix typos 2025-05-22 22:47:36 +08:00
Matthias Krüger
db9525334a
Rollup merge of #141381 - RalfJung:try_cast_aligned-strict-provenance, r=tgross35
try_cast_aligned: avoid bare int-to-ptr casts

This fixes a CI failure in https://github.com/rust-lang/miri-test-libstd caused by strict provenance violations in doctests added in https://github.com/rust-lang/rust/pull/141222.

r? `@tgross35`
Cc `@mathisbot`
2025-05-22 16:04:14 +02:00
Matthias Krüger
c385715806
Rollup merge of #141130 - mejrs:use_self, r=compiler-errors
rustc_on_unimplemented cleanups

Addresses some of the fixmes from https://github.com/rust-lang/rust/pull/139091 and https://github.com/rust-lang/rust/pull/140307.

- switch from `_Self` to `Self` in library
- properly validate that arguments in the `on` filter and the format strings are actually valid

See https://github.com/rust-lang/rustc-dev-guide/pull/2357 for the relevant documentation.
2025-05-22 16:02:30 +02:00
Ralf Jung
09ae053f7a try_cast_aligned: avoid bare int-to-ptr casts 2025-05-22 13:32:36 +02:00
bors
2cd37831b0 Auto merge of #141379 - matthiaskrgr:rollup-g1cz0ic, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #140431 (dont handle bool transmute)
 - #140868 (rustdoc: Fix links with inline code in trait impl docs)
 - #141323 (Add bors environment to CI)
 - #141337 (bump stdarch)
 - #141364 (rustdoc-json: Remove false docs and add test for inline attribute)
 - #141370 (add doc alias `replace_first` for `str::replacen`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-22 05:27:04 +00:00
Matthias Krüger
a31a39833a
Rollup merge of #141370 - WaffleLapkin:hiiii, r=jhpratt
add doc alias `replace_first` for `str::replacen`

`replace_first` is a sensible name for a function, analogous to actually existing `<[_]>::split_first`, for example. (I just saw someone try to search for it)

I think it's reasonable to add such an alias for `replacen`, which replaces the first occurrence of passed a 1.
2025-05-22 07:19:04 +02:00
Matthias Krüger
1735f843af
Rollup merge of #141337 - RalfJung:stdarch, r=Amanieu
bump stdarch

This should unblock https://github.com/rust-lang/rust/pull/135160.
r? `@Amanieu`
2025-05-22 07:19:02 +02:00
bors
6eef33bb39 Auto merge of #137198 - tgross35:cfg-match-rename, r=Amanieu
Rename `cfg_match!` to `cfg_select!`

[`@Nemo157` pointed out](https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605) 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-22 02:14:23 +00:00
waffle
cff790c98e
add doc alias replace_first for str::replacen 2025-05-21 23:43:57 +02:00
Matthias Krüger
b9c6b337ce
Rollup merge of #141341 - folkertdev:limit-VaArgSafe-impls, r=workingjubilee
limit impls of `VaArgSafe` to just types that are actually safe

tracking issue: https://github.com/rust-lang/rust/issues/44930

Retrieving 8- or 16-bit integer arguments from a `VaList` is not safe, because such types are subject to upcasting. See https://github.com/rust-lang/rust/issues/61275#issuecomment-2193942535 for more detail.

This PR also makes the instances of `VaArgSafe` visible in the documentation, and uses a private sealed trait to make sure users cannot create additional impls of `VaArgSafe`, which would almost certainly cause UB.

r? `@workingjubilee`
2025-05-21 22:14:58 +02:00
Matthias Krüger
b5edec2811
Rollup merge of #141230 - xizheyin:issue-141217, r=tgross35
std: fix doctest and explain for `as_slices` and `as_mut_slices` in `VecDeque`

Fixes #141217

r? libs
2025-05-21 22:14:58 +02:00
Matthias Krüger
d4b7915a59
Rollup merge of #140526 - Natr1x:sort-direction-documentation, r=dtolnay
docs: Specify that common sort functions sort in an ascending direction

From [forum discussion](https://users.rust-lang.org/t/is-there-a-way-to-sort-a-slice-in-specifically-ascending-or-descending-order/128998?u=natr1x) it seems like the sorting direction can be expected to always be ascending (in terms of `cmp::Ordering`).

If this is the case then it would be nice to have this stated in the documentation.
2025-05-21 22:14:57 +02:00
xizheyin
46a5c91591 std: fix doctest and explain for as_slices and as_mut_slices in VecDeque
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-21 22:13:23 +08:00
Folkert de Vries
d8a22a281c
limit impls of VaArgSafe to just types that are actually safe
8 and 16-bit integers are subject to upcasting in C, and hence are not reliably safe. users should perform their own casting and deal with the consequences
2025-05-21 15:36:29 +02:00
Ralf Jung
4502ae8c69 bump stdarch 2025-05-21 13:41:58 +02:00
Matthias Krüger
7b4f7a376b
Rollup merge of #137759 - joshtriplett:command-chroot, r=Amanieu
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 "/".

---

ACP: https://github.com/rust-lang/libs-team/issues/551

This PR currently has the tracking issue set to "none"; if the ACP is approved,
I'll file a tracking issue and update the PR.
2025-05-21 11:28:44 +02:00
Matthias Krüger
bb7291e71b
Rollup merge of #141222 - mathisbot:ptr_trycastaligned, r=tgross35
Implement `ptr::try_cast_aligned` and `NonNull::try_cast_aligned`.

Implement three common methods on raw pointers and `NonNull`s: `try_cast_aligned`.

## Related links

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

## About `#[inline]`

Since the result of a call to `align_of` is a power of two known at compile time, the compiler is able to reduce a call to `try_cast_aligned` to only test and sete (or test and jne if followed by `unwrap`), at least on every tier 1 target's arch. This seemed like a good reason to `#[inline]` the function.

- https://godbolt.org/z/ocehvPWMx (raw inlining)
- https://godbolt.org/z/3qa4j4Yrn (comparison with no inlining)
2025-05-21 08:05:21 +02:00
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
Mathis Bottinelli
9d1cf125f8 Implement ptr::try_cast_aligned and NonNull::try_cast_aligned. 2025-05-20 22:51:31 +02: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
Matthias Krüger
8e1ce2059d
Rollup merge of #141282 - DJMcNab:core-float-math-math, r=tgross35
`core_float_math`: Move functions to `math` module

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 the `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.

I believe that I've made the module unstable correctly. I presume that this does not require a test to make sure stable code can't depend on the module existing?

I've left the stability attribute on each function - happy to tweak this if a different pattern is more correct.

Tracking issue for `core_float_math`: https://github.com/rust-lang/rust/issues/137578.
This PR is as requested in https://github.com/rust-lang/rust/pull/138087.

r? `@tgross35`

Recommended reviewing with whitespace hidden.

(This is my first PR to `std/core`/this repository, as far as I can remember)
2025-05-20 20:57:27 +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