about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2024-08-31Fixed some typos in the standard library documentation/commentsranger-ross-5/+5
2024-08-30Squashed `aarch64_unknown_nto_qnx700` supportYuri Astrakhan-5/+8
2024-08-29wasi: Fix sleeping for `Duration::MAX`Alex Crichton-30/+31
This commit fixes an assert in the WASI-specific implementation of thread sleep to ensure that sleeping for a very large period of time blocks instead of panicking. This can come up when testing programs that sleep "forever", for example.
2024-08-28Rollup merge of #129683 - RalfJung:copysign, r=thomccJubilee-12/+32
copysign with sign being a NaN can have non-portable results Follow-up to https://github.com/rust-lang/rust/pull/129559. Cc ```@tgross35``` ```@beetrees``` There's no portable variant we can recommend instead here, is there? Something with a semantics like "if `sign` is a NaN, then return `self` unaltered, otherwise return `self` with the sign changed to that of `sign`"?
2024-08-28Rollup merge of #129401 - ↵Jubilee-1/+0
workingjubilee:partial-initialization-of-stabilization, r=dtolnay,joboet Partially stabilize `feature(new_uninit)` Finished comment period: https://github.com/rust-lang/rust/issues/63291#issuecomment-2183022955 The following API has been stabilized from https://github.com/rust-lang/rust/issues/63291 ```rust impl<T> Box<T> { pub fn new_uninit() -> Box<MaybeUninit<T>> {…} } impl<T> Rc<T> { pub fn new_uninit() -> Rc<MaybeUninit<T>> {…} } impl<T> Arc<T> { pub fn new_uninit() -> Arc<MaybeUninit<T>> {…} } impl<T> Box<[T]> { pub fn new_uninit_slice(len: usize) -> Box<[MaybeUninit<T>]> {…} } impl<T> Rc<[T]> { pub fn new_uninit_slice(len: usize) -> Rc<[MaybeUninit<T>]> {…} } impl<T> Arc<[T]> { pub fn new_uninit_slice(len: usize) -> Arc<[MaybeUninit<T>]> {…} } impl<T> Box<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Box<T> {…} } impl<T> Box<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Box<[T]> {…} } impl<T> Rc<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Rc<T> {…} } impl<T> Rc<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Rc<[T]> {…} } impl<T> Arc<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Arc<T> {…} } impl<T> Arc<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Arc<[T]> {…} } ``` The remaining API is split between new issues - `new_zeroed_alloc`: https://github.com/rust-lang/rust/issues/129396 - `box_uninit_write`: https://github.com/rust-lang/rust/issues/129397 All relevant code is thus either stabilized or split out of that issue, so this closes #63291 as, with the FCP concluded, that issue has served its purpose. try-job: x86_64-rust-for-linux
2024-08-28Rollup merge of #129378 - goffrie:patch-3, r=ChrisDentonJubilee-13/+9
Clean up cfg-gating of ProcessPrng extern This removes a bit of duplication and is consistent with how `api-ms-win-core-synch-l1-2-0` externs are imported.
2024-08-28add guarantee about remove_dir and remove_file error kindsbinarycat-0/+10
approved in ACP https://github.com/rust-lang/libs-team/issues/433
2024-08-28allow BufReader::peek to be called on unsized typesbinarycat-0/+2
2024-08-28copysign with sign being a NaN is non-portableRalf Jung-12/+32
2024-08-27library: Stabilize new_uninit for Box, Rc, and ArcJubilee Young-1/+0
A partial stabilization that only affects: - AllocType<T>::new_uninit - AllocType<T>::assume_init - AllocType<[T]>::new_uninit_slice - AllocType<[T]>::assume_init where "AllocType" is Box, Rc, or Arc
2024-08-27Rollup merge of #129581 - RalfJung:exit, r=joshtriplettMatthias Krüger-0/+9
exit: explain our expectations for the exit handlers registered in a Rust program This documents the position of ``@Amanieu`` and others in https://github.com/rust-lang/rust/issues/126600: a library with an atexit handler that destroys state that other threads could still be working on is buggy. We do not consider it acceptable for a library to say "you must call the following cleanup function before exiting from `main` or calling `exit`". I don't know if this is established ``@rust-lang/libs-api`` consensus so I presume this will have to go through FCP. Given that Rust supports concurrency, I don't think there is any way to write a sound Rust wrapper around a library that has such a required cleanup function: even if we made `exit` unsafe, and the Rust wrapper used the scope-with-callback approach to ensure it can run cleanup code before returning from the wrapper (like `thread::scope`), one could still call this wrapper in a second thread and then return from `main` while the wrapper runs. Making this sound would require `std` to provide a way to "block" returning from `main`, so that while the wrapper runs returning from `main` waits until the wrapper is done... that just doesn't seem feasible. The `exit` docs do not seem like the best place to document this, but I also couldn't think of a better one.
2024-08-27Auto merge of #128134 - joboet:move_pal_alloc, r=cupiverbors-146/+78
std: move allocators to `sys` Part of #117276.
2024-08-27std: move allocators to `sys`joboet-146/+78
2024-08-27Rollup merge of #129559 - RalfJung:float-nan-semantics, r=thomccTrevor Gross-20/+20
float types: document NaN bit pattern guarantees Part of https://github.com/rust-lang/rust/issues/128288: document the guarantees we make for NaN bit patterns. Cc ``@tgross35``
2024-08-26Rollup merge of #129588 - hermit-os:sleep-micros, r=workingjubileeMatthias Krüger-1/+4
pal/hermit: correctly round up microseconds in `Thread::sleep` This fixes the Hermit-related part of https://github.com/rust-lang/rust/issues/129212 and thus the whole issue, since ESP-IDF is already fixed, as far as I understand. Fixes https://github.com/rust-lang/rust/issues/129212 r? `@workingjubilee` CC: `@stlankes`
2024-08-26also update copysign docsRalf Jung-20/+20
2024-08-26pal/hermit: saturate `usleep` microseconds at `u64::MAX`Martin Kröning-1/+2
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
2024-08-25pal/hermit: correctly round up microseconds in `Thread::sleep`Martin Kröning-1/+3
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
2024-08-25exit: explain our expectations for the exit handlers registered in a Rust ↵Ralf Jung-0/+9
program
2024-08-25Rollup merge of #129416 - workingjubilee:partial-move-from-stabilization, ↵Matthias Krüger-0/+1
r=dtolnay library: Move unstable API of new_uninit to new features - `new_zeroed` variants move to `new_zeroed_alloc` - the `write` fn moves to `box_uninit_write` The remainder will be stabilized in upcoming patches, as it was decided to only stabilize `uninit*` and `assume_init`.
2024-08-24Rollup merge of #129501 - RalfJung:miri-rust-backtrace, r=NoratriebMatthias Krüger-1/+1
panicking: improve hint for Miri's RUST_BACKTRACE behavior Should help with https://github.com/rust-lang/miri/issues/3838
2024-08-24panicking: improve hint for Miri's RUST_BACKTRACE behaviorRalf Jung-1/+1
2024-08-23library: Move unstable API of new_uninit to new featuresJubilee Young-0/+1
- `new_zeroed` variants move to `new_zeroed_alloc` - the `write` fn moves to `box_uninit_write` The remainder will be stabilized in upcoming patches, as it was decided to only stabilize `uninit*` and `assume_init`.
2024-08-23Rollup merge of #127623 - lolbinarycat:fix_remove_dir_all, r=AmanieuMatthias Krüger-36/+91
fix: fs::remove_dir_all: treat internal ENOENT as success fixes #127576 try-job: test-various
2024-08-22fix: fs::remove_dir_all: treat ENOENT as successbinarycat-36/+91
fixes #127576 windows implementation still needs some work
2024-08-22Update chown help with a link and adding cap warningPeter Gervai-1/+2
Linked to chown(2) manpage on the web which expands on chown call behaviour.
2024-08-22Expand std::os::unix::fs::chown() doc with a warningPeter Gervai-0/+4
Include warning about losing setuid/gid when chowning, per POSIX.
2024-08-22Rollup merge of #128432 - g0djan:godjan/wasi_prohibit_implicit_unsafe, ↵Matthias Krüger-18/+24
r=tgross35 WASI: forbid `unsafe_op_in_unsafe_fn` for `std::{os, sys}` Part of https://github.com/rust-lang/rust/issues/127747 for WASI try-job: test-various
2024-08-21formatGeoffry Song-9/+2
2024-08-21Clean up cfg-gating of ProcessPrng externGeoffry Song-13/+16
2024-08-21Rollup merge of #129232 - ivmarkov:master, r=workingjubileeMatthias Krüger-6/+24
Fix `thread::sleep` Duration-handling for ESP-IDF Addresses the ESP-IDF specific aspect of https://github.com/rust-lang/rust/issues/129212 #### A short summary of the problems addressed by this PR: ================================================ 1. **Problem 1** - the current implementation of `std::thread::sleep` does not properly round up the passed `Duration` As per the documentation of `std::thread::sleep`, the implementation should sleep _at least_ for the provided duration, but not less. Since the minimum supported resolution of the `usleep` syscall which is used with ESP-IDF is one microsecond, this means that we need to round-up any sub-microsecond nanos to one microsecond. Moreover, in the edge case where the user had passed a duration of < 1000 nanos (i.e. less than one microsecond), the current implementation will _not_ sleep _at all_. This is addressed by this PR. 2. **Problem 2** - the implementation of `usleep` on the ESP-IDF can overflow if the passed number of microseconds is >= `u32::MAX - 1_000_000` This is also addressed by this PR. Extra details for Problem 2: `u32::MAX - 1_000_000` is chosen to accommodate for the longest possible systick on the ESP IDF which is 1000ms. The systick duration is selected when compiling the ESP IDF FreeRTOS task scheduler itself, so we can't know it from within `STD`. The default systick duration is 10ms, and might be lowered down to 1ms. (Making it longer I have never seen, but in theory it can go up to a 1000ms max, even if obviously a one second systick is unrealistic - but we are paranoid in the PR.) While the overflow is reported upstream in the ESP IDF repo[^1], I still believe we should workaround it in the Rust wrappers as well, because it might take time until it is fixed, and they might not fix it for all released ESP IDF versions. For big durations, rather than calling `usleep` repeatedly on the ESP-IDF in chunks of `u32::MAX - 1_000_000`us, it might make sense to call instead with 1_000_000us (one second) as this is the max period that seems to be agreed upon as a safe max period in the `usleep` POSIX spec. On the other hand, that might introduce less precision (as we need to call more times `usleep` in a loop) and, we would be fighting a theoretical problem only, as I have big doubts the ESP IDF will stop supporting durations higher than 1_000_000us - ever - because of backwards compatibility with code which already calls `usleep` on the ESP IDF with bigger durations. [^1]: https://github.com/espressif/esp-idf/issues/14390
2024-08-20Avoid extra `cast()`s after `CStr::as_ptr()`Josh Stone-2/+2
These used to be `&str` literals that did need a pointer cast, but that became a no-op after switching to `c""` literals in #118566.
2024-08-18Rollup merge of #128902 - evanj:evan.jones/env-var-doc, r=workingjubileeTrevor Gross-6/+5
doc: std::env::var: Returns None for names with '=' or NUL byte The documentation incorrectly stated that std::env::var could return an error for variable names containing '=' or the NUL byte. Copy the correct documentation from var_os. var_os was fixed in Commit 8a7a665, Pull Request #109894, which closed Issue #109893. This documentation was incorrectly added in commit f2c0f292, which replaced a panic in var_os by returning None, but documented the change as "May error if ...". Reference the specific error values and link to them.
2024-08-18code review improvementsEvan Jones-9/+5
2024-08-18Fix for issue #129212 for the ESP-IDFivmarkov-6/+24
2024-08-17Auto merge of #126877 - GrigorenkoPV:clone_to_uninit, r=dtolnaybors-0/+100
CloneToUninit impls As per #126799. Also implements it for `Wtf8` and both versions of `os_str::Slice`. Maybe it is worth to slap `#[inline]` on some of those impls. r? `@dtolnay`
2024-08-16Stabilize std::thread::Builder::spawn_uncheckedDavid Tolnay-2/+1
2024-08-16Refer to other docsMaarten-23/+3
2024-08-15Add unordered list with possible values for each constMaarten-64/+125
2024-08-15proposal to expand (a subset of) linux specific socket capabilities.David Carlier-10/+8
to stabilise the quickack part for now, tcp_deferaccept had been added at a later stage.
2024-08-15Format std::env::consts docstringsMaarten-37/+37
This clarifies possible outputs the constants might be.
2024-08-14apply #[optimize(size)] to #[cold] ones and part of the panick machineryThe 8472-2/+9
2024-08-14CommandExt::before_exec: deprecate safety in edition 2024Ralf Jung-3/+11
2024-08-14Auto merge of #129060 - matthiaskrgr:rollup-s72gpif, r=matthiaskrgrbors-2/+14
Rollup of 7 pull requests Successful merges: - #122884 (Optimize integer `pow` by removing the exit branch) - #127857 (Allow to customize `// TODO:` comment for deprecated safe autofix) - #129034 (Add `#[must_use]` attribute to `Coroutine` trait) - #129049 (compiletest: Don't panic on unknown JSON-like output lines) - #129050 (Emit a warning instead of an error if `--generate-link-to-definition` is used with other output formats than HTML) - #129056 (Fix one usage of target triple in bootstrap) - #129058 (Add mw back to review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-14Rollup merge of #128873 - ChrisDenton:windows-targets, r=Mark-SimulacrumMatthias Krüger-41/+1
Add windows-targets crate to std's sysroot With this PR, when backtrace is used as a crate from crates.io it will (once updated) use the real [windows-targets](https://crates.io/crates/windows-targets) crate. But when used from std it'll use std's replacement version. This allows sharing our customized `windows_tagets::link!` macro between std proper and the backtrace crate when used as part of std, ensuring a consistent linking story. This will be especially important once we move to using [`raw-dylib`](https://doc.rust-lang.org/reference/items/external-blocks.html#dylib-versus-raw-dylib) by default.
2024-08-13Make `std::os::darwin` publicMads Marquart-15/+37
This includes `std::os::darwin::fs`, which is re-exported under `std::os::macos::fs` and `std::os::ios::fs`. `std::os::darwin::raw` is not exposed, which means that `MetadataExt::as_raw_stat` isn't available on tvOS, visionOS and watchOS.
2024-08-13Rollup merge of #127857 - tbu-:pr_deprecated_safe_todo, r=petrochenkovMatthias Krüger-2/+14
Allow to customize `// TODO:` comment for deprecated safe autofix Relevant for the deprecation of `CommandExt::before_exit` in #125970. Tracking: - #124866
2024-08-13Auto merge of #129046 - matthiaskrgr:rollup-9x4xgak, r=matthiaskrgrbors-181/+144
Rollup of 7 pull requests Successful merges: - #128643 (Refactor `powerpc64` call ABI handling) - #128655 (std: refactor UNIX random data generation) - #128745 (Remove unused lifetime parameter from spawn_unchecked) - #128841 (bootstrap: don't use rustflags for `--rustc-args`) - #128983 (Slightly refactor `TargetSelection` in bootstrap) - #129026 (CFI: Move CFI ui tests to cfi directory) - #129040 (Fix blessing of rmake tests) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-13Rollup merge of #128745 - dtolnay:spawnunchecked, r=workingjubileeMatthias Krüger-8/+7
Remove unused lifetime parameter from spawn_unchecked Amanieu caught this when reviewing the stabilization proposal in https://github.com/rust-lang/rust/issues/55132. The `'a` lifetime here is useless. The signature is asking the caller of `spawn_unchecked` to "give me any lifetime that is shorter than your F's and T's lifetime", which they can always to with no effect, because arbitrarily short lifetimes exist.
2024-08-13Rollup merge of #128655 - joboet:play_with_the_dice, r=ChrisDentonMatthias Krüger-173/+137
std: refactor UNIX random data generation This PR makes a number of changes to the UNIX randomness implementation: * Use `io::Error` for centralized error handling * Move the file-fallback logic out of the `getrandom`-specific module * Stop redefining the syscalls on macOS and DragonFly, they have appeared in `libc` * Add a `OnceLock` to cache the random device file descriptor