about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2025-05-24reduce clutter... too many importsTshepang Mbambo-8/+8
2025-05-24Path::with_extension: improve examplesTshepang Mbambo-1/+16
2025-05-24Rollup merge of #141505 - RalfJung:catch_unwind, r=NoratriebGuillaume Gomez-5/+5
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-24rename internal panicking::try to catch_unwindRalf Jung-5/+5
2025-05-24Rollup merge of #139254 - Ayush1325:uefi-tcp4-connect, r=joboetMatthias Krüger-30/+178
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-24Rollup merge of #141405 - RalfJung:GetUserProfileDirectoryW, r=ChrisDentonMatthias Krüger-2/+0
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-23GetUserProfileDirectoryW is now documented to always store the sizeRalf Jung-2/+0
2025-05-23Rollup merge of #141398 - Dannyyy93:typos, r=NoratriebMatthias Krüger-3/+3
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-23Rollup merge of #138896 - joboet:process_noalias, r=NoratriebMatthias Krüger-89/+142
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-23std: sys: net: uefi: Implement TCP4 connectAyush Singh-30/+178
- 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-23std: abort the process on failure to allocate a TLS keyjoboet-11/+10
The panic machinery uses TLS, so panicking if no TLS keys are left can lead to infinite recursion (see https://github.com/rust-lang/rust/issues/140798#issuecomment-2872307377). Rather than having separate logic for the panic count and the thread name, just always abort the process if a TLS key allocation fails. This also has the benefit of aligning the key-based TLS implementation with the documentation, which does not mention that a panic could also occur because of resource exhaustion.
2025-05-23std: add safety comments to `CStringArray`joboet-0/+13
2025-05-23std: fix aliasing bug in UNIX process implementationjoboet-89/+129
`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-23Rollup merge of #141109 - oconnor663:pipe_example, r=Mark-SimulacrumMatthias Krüger-12/+26
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-23Rollup merge of #141019 - ehuss:android-doctest-xcompile, r=Mark-SimulacrumMatthias Krüger-6/+21
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-22docs: fix typosDannyyy93-3/+3
2025-05-22Rollup merge of #141130 - mejrs:use_self, r=compiler-errorsMatthias Krüger-1/+1
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-22Auto merge of #137198 - tgross35:cfg-match-rename, r=Amanieubors-2/+2
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-21Rollup merge of #141341 - folkertdev:limit-VaArgSafe-impls, r=workingjubileeMatthias Krüger-1/+1
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-21limit impls of `VaArgSafe` to just types that are actually safeFolkert de Vries-1/+1
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-21Rollup merge of #137759 - joshtriplett:command-chroot, r=AmanieuMatthias Krüger-0/+47
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-21Disable autodiff bootstrappingMarcelo Domínguez-2/+5
2025-05-21Add ReentrantLock::data_ptrJonas Platte-0/+11
2025-05-21Add more docs to new data_ptr methodsJonas Platte-0/+10
2025-05-21Add data_ptr method to Mutex and RwLockJonas Platte-0/+12
2025-05-21Apply suggestions from code reviewJosh Triplett-5/+5
Link `Command::current_dir`. Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2025-05-20Rename `cfg_match!` to `cfg_select!`Trevor Gross-2/+2
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-20Add From<TryLockError> for io::ErrorChristopher Berner-0/+16
This makes error propagation from try_lock() and try_lock_shared() more convenient
2025-05-20Remove unnecessary handling of ERROR_IO_PENDINGChristopher Berner-8/+24
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-20Rollup merge of #141289 - compiler-errors:more-self, r=jhprattMatthias Krüger-2/+2
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`CommandExt::chroot`: Add tracking issueJosh Triplett-1/+1
2025-05-20`CommandExt::chroot`: Document difference to underlying `chroot`Josh Triplett-3/+5
2025-05-20Add `std::os::unix::process::CommandExt::chroot` to safely chroot a child ↵Josh Triplett-0/+45
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`core_float_math`: Move functions to `math` folderDaniel McNab-26/+26
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-20use Self alias in self types rather than manually substituting itMichael Goulet-2/+2
2025-05-20Rollup merge of #141211 - fluiderson:dev, r=thomccStuart Cook-2/+1
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-19Auto merge of #138023 - melrief:97227_impl_Seek_for_Take, r=tgross35bors-1/+173
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-19Rollup merge of #141248 - RalfJung:reentrant-lock-race, r=joboetMatthias Krüger-2/+6
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-19Add `std::io::Seek` instance for `std::io::Take`Mario Pastorelli-1/+173
2025-05-19windows: document that we rely on an undocumented property of ↵Ralf Jung-0/+2
GetUserProfileDirectoryW
2025-05-19fix data race in ReentrantLock fallback for targets without 64bit atomicsRalf Jung-2/+6
2025-05-18Rollup merge of #140628 - joboet:async_signal_safe, r=Mark-SimulacrumLeón Orell Valerian Liehr-58/+215
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-18Rollup merge of #140966 - est31:let_chains_library, r=tgross35León Orell Valerian Liehr-1/+0
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-18replace `try_reserve_exact` with `try_with_capacity` in `std::fs::read`Fluid-2/+1
2025-05-17Auto merge of #138087 - tgross35:core-float-math, r=Amanieubors-867/+29
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-17Rollup merge of #139103 - joboet:abort_dedup, r=tgross35Matthias Krüger-30/+25
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-17Switch library rustc_unimplemented to use `Self` and `This`mejrs-1/+1
2025-05-16discuss deadlocks in the std::io::pipe() exampleJack O'Connor-12/+26
2025-05-17Docs(lib/coll/hm): Add kv pair to `extract_if`'s first sentencePaul Mabileau-1/+1
Make it consistent in this regard with `BTreeMap`'s. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17Docs(lib/extract_if): Unify paragraph about elements mutationPaul Mabileau-2/+2
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>