about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2024-11-20Rollup merge of #130800 - bjoernager:const-mut-cursor, r=joshtriplettMatthias Krüger-2/+4
Mark `get_mut` and `set_position` in `std::io::Cursor` as const. Relevant tracking issue: #130801 The methods `get_mut` and `set_position` can trivially be marked as const due to #57349 being stabilised.
2024-11-20Rollup merge of #129838 - Ayush1325:uefi-process-args, r=joboetMatthias Krüger-12/+56
uefi: process: Add args support - Wrap all args with quotes. - Escape ^ and " inside quotes using ^. - Doing reverse of arg parsing: https://github.com/rust-lang/rust/blob/d571ae851d93541bef826c3c48c1e9ad99da77d6/library/std/src/sys/pal/uefi/args.rs#L81 r​? joboet
2024-11-20re-export `is_loongarch_feature_detected`WANG Rui-0/+2
2024-11-19UniqueRc: platform-specific AsFd/Handle/etc impls to mirror RcZachary S-0/+33
2024-11-19Rollup merge of #133183 - n0toose:improve-remove-dir-docs, r=joboetMatthias Krüger-0/+4
Mention std::fs::remove_dir_all in std::fs::remove_dir
2024-11-19Rollup merge of #125405 - m-ou-se:thread-add-spawn-hook, r=WaffleLapkinMatthias Krüger-7/+175
Add std::thread::add_spawn_hook. Implementation of https://github.com/rust-lang/rfcs/pull/3642
2024-11-19Update doc comments for spawn hook.Mara Bos-2/+6
2024-11-19Address review comments.Mara Bos-7/+6
Co-authored-by: waffle <waffle.lapkin@gmail.com>
2024-11-19Fix tracking issue.Mara Bos-1/+1
2024-11-19Add tracking issue.Mara Bos-2/+2
2024-11-19Use Send + Sync for spawn hooks.Mara Bos-2/+2
2024-11-19Add thread Builder::no_hooks().Mara Bos-7/+24
2024-11-19Update thread spawn hooks.Mara Bos-35/+84
1. Make the effect thread local. 2. Don't return a io::Result from hooks.
2024-11-19Use add_spawn_hook for libtest's output capturing.Mara Bos-4/+0
2024-11-19Add std::thread::add_spawn_hook.Mara Bos-0/+103
2024-11-19Auto merge of #133205 - matthiaskrgr:rollup-xhhhp5u, r=matthiaskrgrbors-0/+3
Rollup of 4 pull requests Successful merges: - #131081 (Use `ConstArgKind::Path` for all single-segment paths, not just params under `min_generic_const_args`) - #132577 (Report the `unexpected_cfgs` lint in external macros) - #133023 (Merge `-Zhir-stats` into `-Zinput-stats`) - #133200 (ignore an occasionally-failing test in Miri) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-19ignore an occasionally-failing test in MiriRalf Jung-0/+3
2024-11-19Rollup merge of #132758 - nnethercote:improve-get_key_value-docs, r=cuviperLeón Orell Valerian Liehr-4/+36
Improve `{BTreeMap,HashMap}::get_key_value` docs. They are unusual methods. The docs don't really describe the cases when they might be useful (as opposed to just `get`), and the examples don't demonstrate the interesting cases at all. This commit improves the docs and the examples.
2024-11-18Mention std::fs::remove_dir_all in std::fs::remove_dirPanagiotis "Ivory" Vasilopoulos-0/+4
2024-11-18wasi/fs: Improve stopping condition for <ReadDir as Iterator>::nextPiotr Osiewicz-14/+17
When upgrading [Zed](https://github.com/zed-industries/zed/pull/19349) to Rust 1.82 I've encountered a test failure in our test suite. Specifically, one of our extension tests started hanging. I've tracked it down to a call to std::fs::remove_dir_all not returning when an extension is compiled with Rust 1.82 Our extension system uses WASM components, thus I've looked at the diff between 1.81 and 1.82 with respect to WASI and found 736f773844e7ebf05ccb827c17b7ad9eb28aa295 As it turned out, calling remove_dir_all from extension returned io::ErrorKind::NotFound in 1.81; the underlying issue is that the ReadDir iterator never actually terminates iteration, however since it loops around, with 1.81 we'd come across an entry second time and fail to remove it, since it would've been removed previously. With 1.82 and 736f773844e7ebf05ccb827c17b7ad9eb28aa295 it is no longer the case, thus we're seeing the hang. This commit makes ReadDir::next adhere to readdir contract, namely it will no longer call readdir once the returned # of bytes is smaller than the size of a passed-in buffer. Previously we'd only terminate the loop if readdir returned 0.
2024-11-18std: allow after-main use of synchronization primitivesjoboet-26/+59
By creating an unnamed thread handle when the actual one has already been destroyed, synchronization primitives using thread parking can be used even outside the Rust runtime. This also fixes an inefficiency in the queue-based `RwLock`: if `thread::current` was not initialized yet, it will create a new handle on every parking attempt without initializing `thread::current`. The private `current_or_unnamed` function introduced here fixes this.
2024-11-18Auto merge of #133160 - jhpratt:rollup-wzj9q15, r=jhprattbors-0/+6
Rollup of 4 pull requests Successful merges: - #132934 (Overhaul the `-l` option parser (for linking to native libs)) - #133142 (rename rustc_const_stable_intrinsic -> rustc_intrinsic_const_stable_indirect) - #133145 (Document alternatives to `static mut`) - #133158 (Subtree update of `rust-analyzer`) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-18Auto merge of #128219 - connortsui20:rwlock-downgrade, r=tgross35bors-261/+662
Rwlock downgrade Tracking Issue: #128203 This PR adds a `downgrade` method for `RwLock` / `RwLockWriteGuard` on all currently supported platforms. Outstanding questions: - [x] ~~Does the `futex.rs` change affect performance at all? It doesn't seem like it will but we can't be certain until we bench it...~~ - [x] ~~Should the SOLID platform implementation [be ported over](https://github.com/rust-lang/rust/pull/128219#discussion_r1693470090) to the `queue.rs` implementation to allow it to support downgrades?~~
2024-11-18Improve `{BTreeMap,HashMap}::get_key_value` docs.Nicholas Nethercote-4/+36
They are unusual methods. The docs don't really describe the cases when they might be useful (as opposed to just `get`), and the examples don't demonstrate the interesting cases at all. This commit improves the docs and the examples.
2024-11-18Document alternatives to `static mut`Kornel-0/+6
2024-11-16Add `DerefMut` for `Lazy[Cell/Lock]` that delegates to the unstable ↵Chayim Refael Friedman-1/+9
`force_mut()`
2024-11-16reduce threads in downgrade testConnor Tsui-1/+1
2024-11-16fix `DOWNGRADED` bit unpreservedConnor Tsui-3/+3
Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-11-16fix memory ordering bug + bad testConnor Tsui-48/+33
This commit fixes a memory ordering bug in the futex implementation (`Relaxed` -> `Release` on `downgrade`). This commit also removes a badly written test that deadlocked and replaces it with a more reasonable test based on an already-tested `downgrade` test from the parking-lot crate.
2024-11-16add safety comments for queue implementationConnor Tsui-13/+25
2024-11-16add `downgrade` to `queue` implementationConnor Tsui-70/+206
This commit adds the `downgrade` method onto the inner `RwLock` queue implementation. There are also a few other style patches included in this commit. Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-11-16modify queue implementation documentationConnor Tsui-191/+214
This commit only has documentation changes and a few things moved around the file. The very few code changes are cosmetic: changes like turning a `match` statement into an `if let` statement or reducing indentation for long if statements. This commit also adds several safety comments on top of `unsafe` blocks that might not be immediately obvious to a first-time reader. Code "changes" are in: - `add_backlinks_and_find_tail` - `lock_contended` A majority of the changes are just expanding the comments from 80 columns to 100 columns.
2024-11-16add `downgrade` to `futex` implementationConnor Tsui-5/+47
2024-11-16add simple `downgrade` implementationsConnor Tsui-0/+17
2024-11-16add `downgrade` method onto `RwLockWriteGuard`Connor Tsui-4/+70
2024-11-16add `RwLock` `downgrade` testsConnor Tsui-2/+122
2024-11-14Rollup merge of #132984 - sunshowers:pipe2, r=tgross35Jubilee-0/+1
[illumos] use pipe2 to create anonymous pipes pipe2 allows the newly-created pipe to atomically be CLOEXEC. pipe2 was added to illumos a long time ago: https://github.com/illumos/illumos-gate/commit/5dbfd19ad5fcc2b779f40f80fa05c1bd28fd0b4e. I've verified that this change passes all of std's tests on illumos.
2024-11-14Rollup merge of #132977 - cberner:fix_solaris, r=tgross35Jubilee-0/+108
Fix compilation error on Solaris due to flock usage PR 130999 added the file_lock feature, but libc does not define flock() for the Solaris platform leading to a compilation error. Additionally, I went through all the Tier 2 platforms and read through their documentation to see whether flock was implemented. This turned up 5 more Unix platforms where flock is not supported, even though it may exist in the libc crate. Fixes https://github.com/rust-lang/rust/issues/132921 Related to #130999
2024-11-14Rollup merge of #132790 - aDotInTheVoid:ioslice-asslice-rides-again, r=cuviperJubilee-6/+95
Add as_slice/into_slice for IoSlice/IoSliceMut. ACP: https://github.com/rust-lang/libs-team/issues/93 Tracking issue: #132818 Based on a623c5233ae7f6b540e5c00f2be02f40b33b0793 (CC `@mpdn)` and #111277 (CC `@Lucretiel).` Closes: #124659 Tracking Issue: TODO try-job: test-various try-job: dist-various-1 try-job: dist-various-2 r? libs
2024-11-14Remove one stray space.Peter Gervai-1/+1
2024-11-14Rollup merge of #133027 - no1wudi:master, r=jhprattGuillaume Gomez-1/+1
Fix a copy-paste issue in the NuttX raw type definition This file is copied from the rtems as initial implementation, and forgot to change the OS name in the comment.
2024-11-14Fix a copy-paste issue in the NuttX raw type definitionHuang Qi-1/+1
This file is copied from the rtems as initial implementation, and forgot to change the OS name in the comment. Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-11-13Rollup merge of #133003 - zachs18:clonetouninit-dyn-compat-u8, r=dtolnayJubilee-21/+21
Make `CloneToUninit` dyn-compatible Make `CloneToUninit` dyn-compatible, by making `clone_to_uninit`'s `dst` parameter `*mut u8` instead of `*mut Self`, so the method does not reference `Self` except in the `self` parameter and is thus dispatchable from a trait object. This allows, among other things, adding `CloneToUninit` as a supertrait bound for `trait Foo` to allow cloning `dyn Foo` in some containers. Currently, this means that `Rc::make_mut` and `Arc::make_mut` can work with `dyn Foo` where `trait Foo: CloneToUninit`. <details><summary>Example</summary> ```rs #![feature(clone_to_uninit)] use std::clone::CloneToUninit; use std::rc::Rc; use std::fmt::Debug; use std::borrow::BorrowMut; trait Foo: BorrowMut<u32> + CloneToUninit + Debug {} impl<T: BorrowMut<u32> + CloneToUninit + Debug> Foo for T {} fn main() { let foo: Rc<dyn Foo> = Rc::new(42_u32); let mut bar = foo.clone(); *Rc::make_mut(&mut bar).borrow_mut() = 37; dbg!(foo, bar); // 42, 37 } ``` </details> Eventually, `Box::<T>::clone` is planned to be converted to use `T::clone_to_uninit`, which when combined with this change, will allow cloning `Box<dyn Foo>` where `trait Foo: CloneToUninit` without any additional `unsafe` code for the author of `trait Foo`.[^1] This PR should have no stable side-effects, as `CloneToUninit` is unstable so cannot be mentioned on stable, and `CloneToUninit` is not used as a supertrait anywhere in the stdlib. This change removes some length checks that could only fail if library UB was already hit (e.g. calling `<[T]>::clone_to_uninit` with a too-small-length `dst` is library UB and was previously detected[^2]; since `dst` does not have a length anymore, this now cannot be detected[^3]). r? libs-api ----- I chose to make the parameter `*mut u8` instead of `*mut ()` because that might make it simpler to pass the result of `alloc` to `clone_to_uninit`, but `*mut ()` would also make sense, and any `*mut ConcreteType` would *work*. The original motivation for [using specifically `*mut ()`](https://github.com/rust-lang/rust/pull/116113#discussion_r1335303908) appears to be `std::ptr::from_raw_parts_mut`, but that now [takes `*mut impl Thin`](https://doc.rust-lang.org/nightly/std/ptr/fn.from_raw_parts.html) instead of `*mut ()`. I have another branch where the parameter is `*mut ()`, if that is preferred. It *could* also take something like `&mut [MaybeUninit<u8>]` to be dyn-compatible but still allow size-checking and in some cases safe writing, but this is already an `unsafe` API where misuse is UB, so I'm not sure how many guardrails it's worth adding here, and `&mut [MaybeUninit<u8>]` might be overly cumbersome to construct for callers compared to `*mut u8` [^1]: Note that `impl<T: CloneToUninit + ?Sized> Clone for Box` must be added before or at the same time as when `CloneToUninit` becomes stable, due to `Box` being `#[fundamental]`, as if there is any stable gap between the stabilization of `CloneToUninit` and `impl<T: CloneToUninit + ?Sized> Clone for Box`, then users could implement both `CloneToUninit for dyn LocalTrait` and separately `Clone for Box<dyn LocalTrait>` during that gap, and be broken by the introduction of `impl<T: CloneToUninit + ?Sized> Clone for Box`. [^2]: Using a `debug_assert_eq` in [`core::clone::uninit::CopySpec::clone_slice`](https://doc.rust-lang.org/nightly/src/core/clone/uninit.rs.html#28). [^3]: This PR just uses [the metadata (length) from `self`](https://github.com/zachs18/rust/blob/e0c1c8bc5058cd3f8831b235c5963ab89840b33b/library/core/src/clone.rs#L286) to construct the `*mut [T]` to pass to `CopySpec::clone_slice` in `<[T]>::clone_to_uninit`.
2024-11-13Rollup merge of #131304 - RalfJung:float-core, r=tgross35Jubilee-363/+0
float types: move copysign, abs, signum to libcore These operations are explicitly specified to act "bitwise", i.e. they just act on the sign bit and do not even quiet signaling NaNs. We also list them as ["non-arithmetic operations"](https://doc.rust-lang.org/nightly/std/primitive.f32.html#nan-bit-patterns), and all the other non-arithmetic operations are in libcore. There's no reason to expect them to require any sort of runtime support, and from [these experiments](https://github.com/rust-lang/rust/issues/50145#issuecomment-997301250) it seems like LLVM indeed compiles them in a way that does not require any sort of runtime support. Nominating for `@rust-lang/libs-api` since this change takes immediate effect on stable. Part of https://github.com/rust-lang/rust/issues/50145.
2024-11-13Fix compilation error on Solaris due to flock usageChristopher Berner-0/+108
PR 130999 added the file_lock feature, but libc does not define flock() for the Solaris platform leading to a compilation error. Additionally, I went through all the Tier 2 platforms and read through their documentation to see whether flock was implemented. This turned up 5 more Unix platforms where flock is not supported, even though it may exist in the libc crate.
2024-11-13[illumos] use pipe2 to create anonymous pipesRain-0/+1
pipe2 allows the newly-created pipe to atomically be CLOEXEC. pipe2 was added to illumos a long time ago: https://github.com/illumos/illumos-gate/commit/5dbfd19ad5fcc2b779f40f80fa05c1bd28fd0b4e. I've verified that this change passes all tests.
2024-11-12Make `CloneToUninit` dyn-compatibleZachary S-21/+21
2024-11-12Rollup merge of #132869 - ↵Matthias Krüger-0/+4
lolbinarycat:library-fix-too_long_first_doc_paragraph, r=tgross35 split up the first paragraph of doc comments for better summaries used `./x clippy -Aclippy::all '-Wclippy::too_long_first_doc_paragraph' library/core library/alloc` to find these issues.
2024-11-12Auto merge of #132919 - matthiaskrgr:rollup-ogghyvp, r=matthiaskrgrbors-0/+449
Rollup of 7 pull requests Successful merges: - #120077 (Add Set entry API ) - #132144 (Arbitrary self types v2: (unused) Receiver trait) - #132297 (Document some `check_expr` methods, and other misc `hir_typeck` tweaks) - #132820 (Add a default implementation for CodegenBackend::link) - #132881 (triagebot: Autolabel rustdoc book) - #132912 (Simplify some places that deal with generic parameter defaults) - #132916 (Unvacation fmease) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-12a release operation synchronizes with an acquire operationxmh0511-3/+3