summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2025-08-01thread name in stack overflow messagejoboet-29/+78
2025-07-07Null terminate UNICODE_STRINGsChris Denton-2/+12
2025-06-23Update version placeholdersJosh Stone-22/+22
2025-06-22Stop dbg! macro yapping about format modifiersmejrs-1/+8
2025-06-20Add diagnostic items for ClippySamuel Tardieu-0/+2
2025-06-20Rollup merge of #141990 - Qelxiros:141975-unix_send_signal, ↵Trevor Gross-8/+67
r=ChrisDenton,tgross35 Implement send_signal for unix child processes Tracking issue: rust-lang/rust#141975 There are two main differences between my implementation and the Public API section of the tracking issue. ~First, `send_signal` requires a mutable reference, like `Child::kill`.~ Second, `ChildExt` has `Sealed` as a supertrait, bringing it more in line with other extension traits like `CommandExt`. try-job: `dist-various*` try-job: `test-various*`
2025-06-19Auto merge of #141864 - Berrysoft:cygwin-path, r=ChrisDentonbors-173/+300
Handle win32 separator for cygwin paths This PR handles a issue that cygwin actually supports Win32 path, so we need to handle the Win32 prefix and separaters. r? `@mati865` cc `@jeremyd2019` ~~Not sure if I should handle the prefix like the windows target... Cygwin *does* support win32 paths directly going through the APIs, but I think it's not the recommended way.~~ Here I just use `cygwin_conv_path` because it handles both cygwin and win32 paths correctly and convert them into absolute POSIX paths. UPDATE: Windows path prefix is handled.
2025-06-18add ChildExt(::send_signal)Jeremy Smart-8/+67
2025-06-17Rollup merge of #142517 - ChrisDenton:anon-pipe, r=Mark-SimulacrumJacob Pratt-86/+142
Windows: Use anonymous pipes in Command When setting `Stdio::pipe` on `Command` we want to create an anonymous pipe that can be used asynchronously (at least on our end). Usually we'd use [`CreatePipe`](https://learn.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-createpipe) to open anonymous pipes but unfortunately it opens pipes for synchronous access. The alternative is to use [`CreateNamedPipeW`](https://learn.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-createnamedpipew) which does allow asynchronous access but that requires giving a file name to the pipe. So we currently have this awful hack where we attempt to emulate anonymous pipes using `CreateNamedPipeW` by attempting to create a unique name and looping until we find one that doesn't already exist. The better option is to use the lower level [`NtCreateNamedPipeFile`](https://learn.microsoft.com/en-us/windows/win32/devnotes/nt-create-named-pipe-file) (which is used internally by both `CreatePipe` and `CreateNamedPipeW`). This function wasn't documented until a few years ago but now that it is it's ok for us to use it. try-job: *msvc* try-job: *mingw*
2025-06-16Rollup merge of #142236 - yotamofek:pr/std/pathbuf-extend-docs, r=tgross35Jakub Beránek-0/+27
Add documentation for `PathBuf`'s `FromIterator` and `Extend` impls I think it's not very obvious that `PathBuf`'s `Extend` and `FromIterator` impls work like `PathBuf::push`, so I think these should be documented. I'm not very happy with the wording and examples, open to suggestions :)
2025-06-16Add documentation for `PathBuf`'s `FromIterator` and `Extend` implsYotam Ofek-0/+27
2025-06-16Handle win32 separator & prefixes for cygwin paths王宇逸-173/+300
2025-06-15Windows: Use anonymous pipes in CommandChris Denton-86/+142
2025-06-15Stabilize "file_lock" featureChristopher Berner-15/+10
2025-06-14Rollup merge of #141493 - tamird:addreskind-bytestr, r=joshtriplettMatthias Krüger-4/+14
Delegate `<SocketAddr as Debug>` to `ByteStr` This allows UTF-8 characters to be printed without escapes, rather than just ASCII. r? ``@joshtriplett``
2025-06-13Remove "intermittent" wording from `ReadDir`Chris Denton-3/+2
2025-06-12Delegate `<SocketAddr as Debug>` to `ByteStr`Tamir Duberstein-4/+14
This allows UTF-8 characters to be printed without escapes, rather than just ASCII.
2025-06-10Rollup merge of #142102 - kiseitai3:141714_stdin_read_to_string_docs, r=tgross35León Orell Valerian Liehr-0/+40
docs: Small clarification on the usage of read_to_string and read_to_end trait methods Small clarification on the usage of read_to_string and read_to_end trait methods. The goal is to make it clear that these trait methods will become locked up if attempting to read to the end of stdin (which is a bit non-sensical unless the other end closes the pipe). Fixes: rust-lang/rust#141714
2025-06-10docs: Small clarification on the usage of read_to_string and read_to_end ↵kiseitai3-0/+40
trait methods
2025-06-09Auto merge of #138062 - LorrensP-2158466:miri-enable-float-nondet, r=RalfJungbors-20/+20
Enable Non-determinism of float operations in Miri and change std tests Links to [#4208](https://github.com/rust-lang/miri/issues/4208) and [#3555](https://github.com/rust-lang/miri/issues/3555) in Miri. Non-determinism of floating point operations was disabled in rust-lang/rust#137594 because it breaks the tests and doc-tests in core/coretests and std. This PR enables some of them. This pr includes the following changes: - Enables the float non-determinism but with a lower relative error of 4ULP instead of 16ULP - These operations now have a fixed output based on the C23 standard, except the pow operations, this is tracked in [#4286](https://github.com/rust-lang/miri/issues/4286#issue-3010677983) - Changes tests that made incorrect assumptions about the operations, not to make that assumption anymore (from `assert_eq!` to `assert_approx_eq!`. - Changed the doctests of the stdlib of these operations to compare against fixed constants instead of `f*::EPSILON`, which now succeed with Miri and `-Zmiri-many-seeds` - Added a constant `APPROX_DELTA` in `std/tests/floats/f32.rs` which is used for approximation tests, but with a different value when run in Miri. This is to make these tests succeed. - Added tests in the float tests of Miri to test the C23 behaviour. Fixes https://github.com/rust-lang/miri/issues/4208
2025-06-09Rollup merge of #142238 - RalfJung:nonnull_provenance, r=workingjubileeTrevor Gross-1/+0
stabilize nonnull_provenance Fixes https://github.com/rust-lang/rust/issues/135243 FCP passed in https://github.com/rust-lang/rust/issues/135243
2025-06-09Rollup merge of #142192 - Urgau:dedup-f16-f128-test-attrs, r=tgross35Matthias Krüger-134/+2
De-duplicate f16 & f128 doctest attributes Now that rustdoc supports `#[doc(test(attr(...)))]` at every level, thanks to https://github.com/rust-lang/rust/pull/140560, we can de-duplicate the f16 & f128 doctest attributes. Unfortunately we can de-duplicate the `cfg`s attribute as rustdoc would complain about missing `main`, but it's already much better than before. Addresses https://github.com/rust-lang/rust/pull/140323/files#r2062702761 r? `@tgross35`
2025-06-09Rollup merge of #129121 - devnexen:stabilize_ext_linux_tcp_layer, r=tgross35Matthias Krüger-10/+8
Stabilize `tcp_quickack` to stabilise the quickack part for now, tcp_deferaccept had been added at a later stage. The related API calls are the following ```rust // std::os::linux::net // sealed trait, implemented for std::net::TcpStream pub trait TcpStreamExt: Sealed{ fn quickack(&self) -> io::Result<bool>; fn set_quickack(&self, quickack: bool) -> io::Result<()>; } ``` Closes: https://github.com/rust-lang/rust/issues/96256
2025-06-09stabilize nonnull_provenanceRalf Jung-1/+0
2025-06-08Rollup merge of #142053 - heiher:loong32-none, r=wesleywiserJubilee-1/+4
Add new Tier-3 targets: `loongarch32-unknown-none*` MCP: https://github.com/rust-lang/compiler-team/issues/865 NOTE: LoongArch32 ELF object support is available starting with object v0.37.0.
2025-06-08De-duplicate f16 & f128 doctest attributesUrgau-134/+2
2025-06-07Rollup merge of #137992 - its-the-shrimp:stabilise_os_string_pathbuf_leak, ↵Jacob Pratt-2/+2
r=dtolnay Stabilise `os_string_pathbuf_leak` This PR stabilises `#[feature(os_string_pathbuf_leak)]`, which defines 2 new methods in the std: ```rs impl OsString { pub fn leak<'a>(self) -> &'a mut OsStr; } impl PathBuf { pub fn leak<'a>(self) -> &'a mut Path; } ``` ACP: https://github.com/rust-lang/libs-team/issues/389 Tracking issue: https://github.com/rust-lang/rust/issues/125965 Implementation: https://github.com/rust-lang/rust/pull/125966
2025-06-06Rollup merge of #141471 - RalfJung:unsafe-fn-in-trait, r=traviscrossGuillaume Gomez-16/+11
unsafe keyword docs: emphasize that an unsafe fn in a trait does not get to choose its safety contract Inspired by discussion in https://github.com/rust-lang/rust/issues/139368. Cc `@hanna-kruppe`
2025-06-06Rollup merge of #140418 - tgross35:std-c-size_t, r=workingjubileeGuillaume Gomez-0/+2
Reexport types from `c_size_t` in `std` These are unstably available in `core` and should be in `std` too, but are not currently reexported. Resolve this here. Tracking issue: https://github.com/rust-lang/rust/issues/88345
2025-06-06unsafe keyword docs: emphasize that an unsafe fn in a trait does not get to ↵Ralf Jung-16/+11
choose its safety contract
2025-06-06Stabilised `os_string_pathbuf_leak`schvv31n-2/+2
2025-06-06Add new Tier-3 targets: `loongarch32-unknown-none*`WANG Rui-1/+4
MCP: https://github.com/rust-lang/compiler-team/issues/865
2025-06-06Rollup merge of #142091 - thaliaarchi:aix-getenv, r=workingjubileeMatthias Krüger-1/+1
Fix AIX build Fix rust-lang/rust#141543. `getenv` was moved out of this file to `sys::env::getenv` in rust-lang/rust#140143. Replace its usage with `std::env::var_os`, the publicly exposed version. This matches the other usages of the same function in this file.
2025-06-05Fix AIX buildThalia Archibald-1/+1
2025-06-05Clarify description of `Seek::stream_len`Tobias Bucher-1/+1
It can only describe the inner workings of the default implementation, other implementations might not be implemented using seeks at all.
2025-06-05Optimize `Seek::stream_len` impl for `File`Tobias Bucher-10/+89
It uses the file metadata on Unix with a fallback for files incorrectly reported as zero-sized. It uses `GetFileSizeEx` on Windows. This reduces the number of syscalls needed for determining the file size of an open file from 3 to 1.
2025-06-05change tests to use fixed constants to let them pass with miriLorrensP-2158466-20/+20
2025-06-04Rollup merge of #141467 - cyrgani:const-empty-stringlikes, r=AmanieuMatthias Krüger-5/+7
make `OsString::new` and `PathBuf::new` unstably const Since #129041, `String::into_bytes` is `const`, which allows making `OsString::new` and `PathBuf::new` unstably const now. Not sure what the exact process for this is; does it need an ACP?
2025-06-03Rollup merge of #141925 - cuviper:vestigial-bootstrap, r=workingjubileeMatthias Krüger-8/+2
Remove bootstrap cfgs from library/ These `cfg(bootstrap)` are always false now that rust-lang/rust#119899 has landed, and likewise `cfg(not(bootstrap))` is always true. Therefore, we don't need to wait for the usual stage0 bump to clean these up.
2025-06-03Rollup merge of #141455 - joboet:tls_exhaustion_abort, r=tgross35Matthias Krüger-11/+10
std: abort the process on failure to allocate a TLS key 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-06-03Enable Float non-determinism in miri. Update and add tests and changeLorrensP-2158466-18/+18
change tests in std, core and coretests.
2025-06-03Rollup merge of #140715 - lukaslueg:oncecellsyncdocs, r=tgross35Matthias Krüger-5/+13
Clarify &mut-methods' docs on sync::OnceLock Three small changes to the docs of `sync::OnceLock`: * The docs for `OnceLock::take()` used to [say](https://doc.rust-lang.org/std/sync/struct.OnceLock.html#method.take) "**Safety** is guaranteed by requiring a mutable reference." (emphasis mine). While technically correct, imho its not necessary to even mention safety - as opposed to unsafety - here: Safety never comes up wrt `OnceLock`, as there is (currently) no way to interact with a `OnceLock` in an unsafe way; there are no unsafe methods on `OnceLock`, so there is "safety" guarantee required anywhere. What we simply meant to say is "**Synchronization** is guaranteed...". * I've add that phrase to the other methods of `OnceLock` which take a `&mut self`, to highlight the fact that having a `&mut OnceLock` guarantees that synchronization with other threads is not required. This is the same as with [`Mutex::get_mut()`](https://doc.rust-lang.org/std/sync/struct.Mutex.html#method.get_mut), [`Cell::get_mut()`](https://doc.rust-lang.org/std/cell/struct.Cell.html#method.get_mut), and others. * In that spirit, the half-sentence "or being initialized" was removed from `get_mut()`, as there is no way that the `OnceLock` is being initialized while we are holding `&mut` to it. Probably a copy&paste from `.get()`
2025-06-02Remove more library bootstrapJosh Stone-6/+1
2025-06-02Remove bootstrap cfgs from library/Josh Stone-2/+1
2025-06-01Rollup merge of #141832 - workingjubilee:explain-what-toctou-races-are, ↵Jacob Pratt-8/+19
r=thomcc,ChrisDenton library: explain TOCTOU races in `fs::remove_dir_all` In the previous description it said there was a TOCTOU race but did not explain exactly what the problem was. I sat down with the CVE, reviewed its text, and created this explanation. This context should hopefully help people understand the actual risk as-such. Incidentally, it also fixes the capitalization on the name of Redox OS. Original CVE and advisory: - CVE: https://www.cve.org/CVERecord?id=CVE-2022-21658 - security advisory: https://groups.google.com/g/rustlang-security-announcements/c/R1fZFDhnJVQ?pli=1 - github cross-post: https://github.com/rust-lang/rust/security/advisories/GHSA-r9cc-f5pr-p3j2
2025-05-31library: explain TOCTOU races in `fs::remove_dir_all`Jubilee Young-8/+19
In the previous description it said there was a TOCTOU race but did not explain exactly what the problem was. I sat down with the CVE, reviewed its text, and created this explanation. This context should hopefully help people understand the actual risk as-such. Incidentally, it also fixes the capitalization on the name of Redox OS.
2025-05-31Add const support for float rounding methodsRuan Comelli-12/+25
Add const support for the float rounding methods floor, ceil, trunc, fract, round and round_ties_even. This works by moving the calculation logic from src/tools/miri/src/intrinsics/mod.rs into compiler/rustc_const_eval/src/interpret/intrinsics.rs. All relevant method definitions were adjusted to include the `const` keyword for all supported float types: f16, f32, f64 and f128. The constness is hidden behind the feature gate feature(const_float_round_methods) which is tracked in https://github.com/rust-lang/rust/issues/141555 This commit is a squash of the following commits: - test: add tests that we expect to pass when float rounding becomes const - feat: make float rounding methods `const` - fix: replace `rustc_allow_const_fn_unstable(core_intrinsics)` attribute with `#[rustc_const_unstable(feature = "f128", issue = "116909")]` in `library/core/src/num/f128.rs` - revert: undo update to `library/stdarch` - refactor: replace multiple `float_<mode>_intrinsic` rounding methods with a single, parametrized one - fix: add `#[cfg(not(bootstrap))]` to new const method tests - test: add extra sign tests to check `+0.0` and `-0.0` - revert: undo accidental changes to `round` docs - fix: gate `const` float round method behind `const_float_round_methods` - fix: remove unnecessary `#![feature(const_float_methods)]` - fix: remove unnecessary `#![feature(const_float_methods)]` [2] - revert: undo changes to `tests/ui/consts/const-eval/float_methods.rs` - fix: adjust after rebase - test: fix float tests - test: add tests for `fract` - chore: add commented-out `const_float_round_methods` feature gates to `f16` and `f128` - fix: adjust NaN when rounding floats - chore: add FIXME comment for de-duplicating float tests - test: remove unnecessary test file `tests/ui/consts/const-eval/float_methods.rs` - test: fix tests after upstream simplification of how float tests are run
2025-05-31Auto merge of #141685 - orlp:inplace-tls-drop, r=joboetbors-29/+51
Do not move thread-locals before dropping Fixes rust-lang/rust#140816. I also (potentially) improved the speed of `get_or_init` a bit by having an explicit hot/cold path. We still move the value before dropping in the event of a recursive initialization (leading to double-initialization with one value being silently dropped). This is the old behavior, but changing this to panic instead would involve changing tests and also the other OS-specific `thread_local/os.rs` implementation, which is more than I'd like in this PR.
2025-05-30Address review comments.Orson Peters-0/+7
2025-05-29Make `std/src/num` mirror `core/src/num`Trevor Gross-2/+8
The float modules in `std` are currently top-level but for `core`, they are nested within the `num` directory and referenced by `#[path = ...]`. For consistency, adjust `std` to use the same structure as `core`. Also change the `f16` and `f128` gates from outer attributes to inner attributes like `core` has.