about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-06-22Add new unit test `test_try_downcast_inner`Jiahao XU-1/+52
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-22Add new unstable API `Error::try_downgrade_inner`Jiahao XU-0/+57
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-22Impl `io::error::repr_bitpacked::Repr::new`Jiahao XU-0/+9
that accepts `ErrorData<Box<Custom>>` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-22Impl `io::error::repr_unpacked::Repr::new`Jiahao XU-0/+4
that accepts `ErrorData<Box<Custom>>` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-22Address reviewer commentsRaoul Strackx-5/+10
2022-06-22Rollup merge of #96768 - m-ou-se:futex-fuchsia, r=tmandryYuki Okushi-0/+52
Use futex based thread parker on Fuchsia.
2022-06-21`impl<T: AsFd> AsFd for {Arc,Box}<T>`Joshua Nelson-3/+33
2022-06-21`impl<T: AsRawFd> for {Arc,Box}<T>`Joshua Nelson-0/+32
This allows implementing traits that require a raw FD on Arc and Box. Previously, you'd have to add the function to the trait itself: ```rust trait MyTrait { fn as_raw_fd(&self) -> RawFd; } impl<T: MyTrait> MyTrait for Arc<T> { fn as_raw_fd(&self) -> RawFd { (**self).as_raw_fd() } } ```
2022-06-21Rollup merge of #98330 - conradludgate:io-slice-mut-docs, r=Dylan-DPCYuki Okushi-8/+8
update ioslice docs to use shared slices I noticed that IoSlice docs were taking unnecessary mut slices, when they only accept shared slices
2022-06-21Rollup merge of #98313 - m-ou-se:fix-comments, r=joshtriplettYuki Okushi-7/+6
Remove lies in comments. > does not have a const constructor > pub const fn new() -> Self 🤔
2022-06-21Rollup merge of #94033 - ↵Yuki Okushi-6/+8
joshtriplett:documentation-is-running-better-go-catch-it, r=m-ou-se Improve docs for `is_running` to explain use case
2022-06-21Use futex based thread parker on Fuchsia.Mara Bos-0/+52
2022-06-21update ioslice docs to use shared slicesConrad Ludgate-8/+8
2022-06-20Remove lies in comments.Mara Bos-7/+6
2022-06-20Improve docs for `is_running` to explain use caseJosh Triplett-6/+8
2022-06-20Rollup merge of #97837 - sunfishcode:sunfishcode/proc-self-mem, r=m-ou-seDylan DPC-0/+19
Document Rust's stance on `/proc/self/mem` Add documentation to `std::os::unix::io` describing Rust's stance on `/proc/self/mem`, treating it as an external entity which is outside the scope of Rust's safety guarantees.
2022-06-20Rollup merge of #97150 - ChrisDenton:stdio-create_pipe, r=m-ou-seDylan DPC-0/+16
`Stdio::makes_pipe` Wrappers around `std::process::Command` may want to be able to override pipe creation. However, [`std::process::Stdio`](https://doc.rust-lang.org/std/process/struct.Stdio.html) is opaque so there's no way to tell if `Command` was told to create new pipes or not. This is in some ways a more generic (and cross-platform) alternative to #97149. However, unlike that feature, this comes with the price of the user needing to actually create their own pipes rather than reusing the std one. So I think it stands (or not) on its own. # Example ```rust #![feature(stdio_makes_pipe)] use std::process::Stdio; let io = Stdio::piped(); assert_eq!(io.makes_pipe(), true); ```
2022-06-20Rollup merge of #97149 - ChrisDenton:win_async_pipes, r=m-ou-seDylan DPC-0/+40
Windows: `CommandExt::async_pipes` Discussed in https://github.com/tokio-rs/tokio/issues/4670 was the need for third party crates to be able to force `process::Command::spawn` to create pipes as async. This implements the suggestion for a `async_pipes` method that gives third party crates that option. # Example: ```rust use std::process::{Command, Stdio}; Command::new("cmd") .async_pipes(true) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() .unwrap(); ```
2022-06-20Rollup merge of #94855 - m-ou-se:advance-slice-panic-docs, r=kennytmDylan DPC-20/+38
Panic when advance_slices()'ing too far and update docs. This updates advance_slices() to panic when advancing too far, like advance() already does. And updates the docs to say so. See https://github.com/rust-lang/rust/issues/62726#issuecomment-1065253213
2022-06-20Windows: `CommandExt::async_pipes`Chris Denton-0/+40
2022-06-20`Stdio::make_pipe`Chris Denton-0/+16
2022-06-20Leak pthreax_rwlock_t when it's dropped while locked.Mara Bos-0/+16
2022-06-20Fix typo in `HashMap::drain` docsnils-1/+1
It's a map, not a vector.
2022-06-20Rollup merge of #97912 - Kixunil:stabilize_path_try_exists, r=dtolnayYuki Okushi-8/+17
Stabilize `Path::try_exists()` and improve doc This stabilizes the `Path::try_exists()` method which returns `Result<bool, io::Error>` instead of `bool` allowing handling of errors unrelated to the file not existing. (e.g permission errors) Along with the stabilization it also: * Warns that the `exists()` method is error-prone and suggests to use the newly stabilized one. * Suggests it instead of `metadata()` to handle errors. * Mentions TOCTOU bugs to avoid false assumption that `try_exists()` is completely safe fixed version of `exists()`. * Renames the feature of still-unstable `std::fs::try_exists()` to `fs_try_exists` to avoid name conflict. The tracking issue #83186 remains open to track `fs_try_exists`.
2022-06-19Fix documentation for with_capacity and reserve families of methodsjmaargh-37/+53
Documentation for the following methods with_capacity with_capacity_in with_capacity_and_hasher reserve reserve_exact try_reserve try_reserve_exact was inconsistent and often not entirely correct where they existed on the following types Vec VecDeque String OsString PathBuf BinaryHeap HashSet HashMap BufWriter LineWriter since the allocator is allowed to allocate more than the requested capacity in all such cases, and will frequently "allocate" much more in the case of zero-sized types (I also checked BufReader, but there the docs appear to be accurate as it appears to actually allocate the exact capacity). Some effort was made to make the documentation more consistent between types as well. Fix with_capacity* methods for Vec Fix *reserve* methods for Vec Fix docs for *reserve* methods of VecDeque Fix docs for String::with_capacity Fix docs for *reserve* methods of String Fix docs for OsString::with_capacity Fix docs for *reserve* methods on OsString Fix docs for with_capacity* methods on HashSet Fix docs for *reserve methods of HashSet Fix docs for with_capacity* methods of HashMap Fix docs for *reserve methods on HashMap Fix expect messages about OOM in doctests Fix docs for BinaryHeap::with_capacity Fix docs for *reserve* methods of BinaryHeap Fix typos Fix docs for with_capacity on BufWriter and LineWriter Fix consistent use of `hasher` between `HashMap` and `HashSet` Fix warning in doc test Add test for capacity of vec with ZST Fix doc test error
2022-06-19Rollup merge of #98233 - RalfJung:ref-alloc, r=thomccDylan DPC-4/+4
Remove accidental uses of `&A: Allocator` Cc https://github.com/rust-lang/rust/issues/98232 Fixes https://github.com/rust-lang/rust/issues/98176 (for real this time)
2022-06-19Auto merge of #97791 - m-ou-se:const-locks, r=m-ou-sebors-6/+26
Make {Mutex, Condvar, RwLock}::new() const. This makes it possible to have `static M: Mutex<_> = Mutex::new(..);` 🎉 Our implementations [on Linux](https://github.com/rust-lang/rust/pull/95035), [on Windows](https://github.com/rust-lang/rust/pull/77380), and various BSDs and some tier 3 platforms have already been using a non-allocating const-constructible implementation. As of https://github.com/rust-lang/rust/pull/97647, the remaining platforms (most notably macOS) now have a const-constructible implementation as well. This means we can finally make these functions publicly const. Tracking issue: https://github.com/rust-lang/rust/issues/93740
2022-06-19Add comment explaining why we use NonNullRobin Raymond-0/+4
2022-06-19Add safety commentsRobin Raymond-6/+9
2022-06-19Documentation typoRobin Raymond-1/+1
2022-06-19*const to NonNull plus documentationRobin Raymond-3/+12
2022-06-19Address commentsRobin Raymond-3/+3
2022-06-19More formattingRobin Raymond-1/+1
2022-06-19FormattingRobin Raymond-2/+5
2022-06-19Make RwLockReadGuard covariantRobin Raymond-5/+18
2022-06-19Rollup merge of #98165 - WaffleLapkin:once_things_renamings, r=m-ou-seMatthias Krüger-770/+795
once cell renamings This PR does the renamings proposed in https://github.com/rust-lang/rust/issues/74465#issuecomment-1153703128 - Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}` - Move/rename `lazy::{SyncOnceCell, SyncLazy}` to `sync::{OnceLock, LazyLock}` (I used `Lazy...` instead of `...Lazy` as it seems to be more consistent, easier to pronounce, etc) ```@rustbot``` label +T-libs-api -T-libs
2022-06-18Auto merge of #97924 - cuviper:unguarded-poison, r=Mark-Simulacrumbors-8/+15
Avoid `thread::panicking()` in non-poisoning methods of `Mutex` and `RwLock` `Mutex::lock()` and `RwLock::write()` are poison-guarded against panics, in that they set the poison flag if a panic occurs while they're locked. But if we're already in a panic (`thread::panicking()`), they leave the poison flag alone. That check is a bit of a waste for methods that never set the poison flag though, namely `get_mut()`, `into_inner()`, and `RwLock::read()`. These use-cases are now split to avoid that unnecessary call.
2022-06-18make std not use &A: Allocator instanceRalf Jung-4/+4
2022-06-17Impl Termination for Infallible and then make the Result impls of ↵Aria Beingessner-22/+15
Termination into a blanket This allows things like `Result<ExitCode, E>` to 'just work'
2022-06-17Rollup merge of #97844 - ChrisDenton:dont-panic, r=JohnTitorDylan DPC-4/+5
Windows: No panic if function not (yet) available In some situations (e.g. #97814) it is possible for required functions to be called before they've had a chance to be loaded. Therefore, we make it possible to recover from this situation simply by looking at error codes. `@rustbot` label +O-windows
2022-06-17Rollup merge of #95392 - Xuanwo:stablize_try_reserve_2, r=dtolnayDylan DPC-6/+4
std: Stabilize feature try_reserve_2 This PR intends to stabilize feature `try_reserve_2`, closes https://github.com/rust-lang/rust/issues/91789 This PR will also replace the previous PR: https://github.com/rust-lang/rust/pull/95139
2022-06-17Auto merge of #98143 - cuviper:futex-rwlock-inline, r=thomccbors-0/+9
Add `#[inline]` to small fns of futex `RwLock` The important methods like `read` and `write` were already inlined, which can propagate all the way to inlining in user code, but these small state functions were left behind as normal calls. They should almost always be inlined as well, as they're just a few instructions.
2022-06-17Rollup merge of #98169 - pierwill:dyn-disp, r=JohnTitorYuki Okushi-1/+2
Keyword docs: Link to wikipedia article for dynamic dispatch
2022-06-17Rollup merge of #98118 - steffahn:scoped-threads-nll-test, r=m-ou-seYuki Okushi-0/+13
Test NLL fix of bad lifetime inference for reference captured in closure. This came up as a use-case for `thread::scope` API that only compiles successfully since `feature(nll)` got stabilized recently. Closes #93203 which had been re-opened for tracking this very test case to be added.
2022-06-16Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock`Maybe Waffle-771/+795
2022-06-16Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}`Maybe Waffle-3/+4
2022-06-16Keyword docs: Link to wikipedia article for dynamic dispatchpierwill-1/+2
2022-06-16Auto merge of #97842 - notriddle:notriddle/tuple-docs, r=jsha,GuillaumeGomezbors-6/+70
Improve the tuple and unit trait docs * Reduce duplicate impls; show only the `(T,)` and include a sentence saying that there exists ones up to twelve of them. * Show `Copy` and `Clone`. * Show auto traits like `Send` and `Sync`, and blanket impls like `Any`. Here's the new version: * <https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html> * <https://notriddle.com/notriddle-rustdoc-test/std/primitive.unit.html>
2022-06-16Leak pthreax_mutex_t when it's dropped while locked.Mara Bos-4/+35
2022-06-16Rollup merge of #98125 - KarlWithK:entry_add_modify_doc, r=Dylan-DPCMatthias Krüger-2/+4
Entry and_modify doc This PR modifies the documentation for [HashMap](https://doc.rust-lang.org/std/collections/struct.HashMap.html#) and [BTreeMap](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html#) by introducing examples for `and_modify`. `and_modify` is a function that tends to give more idiomatic rust code when dealing with these data structures -- yet it lacked examples and was hidden away. This PR adds that and addresses #98122. I've made some choices which I tried to explain in my commits. This is my first time contributing to rust, so hopefully, I made the right choices.