about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-06-25Auto merge of #98486 - matthiaskrgr:rollup-u7m508x, r=matthiaskrgrbors-89/+274
Rollup of 9 pull requests Successful merges: - #96412 (Windows: Iterative `remove_dir_all`) - #98126 (Mitigate MMIO stale data vulnerability) - #98149 (Set relocation_model to Pic on emscripten target) - #98194 (Leak pthread_{mutex,rwlock}_t if it's dropped while locked.) - #98298 (Point to type parameter definition when not finding variant, method and associated item) - #98311 (Reverse folder hierarchy) - #98401 (Add tracking issues to `--extern` option docs.) - #98429 (Use correct substs in enum discriminant cast) - #98431 (Suggest defining variable as mutable on `&mut _` type mismatch in pats) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-06-25Rollup merge of #98194 - m-ou-se:leak-locked-pthread-mutex, r=AmanieuMatthias Krüger-4/+51
Leak pthread_{mutex,rwlock}_t if it's dropped while locked. Fixes https://github.com/rust-lang/rust/issues/85434.
2022-06-25Rollup merge of #98126 - fortanix:raoul/mitigate_stale_data_vulnerability, ↵Matthias Krüger-10/+142
r=cuviper Mitigate MMIO stale data vulnerability Intel publicly disclosed the MMIO stale data vulnerability on June 14. To mitigate this vulnerability, compiler changes are required for the `x86_64-fortanix-unknown-sgx` target. cc: ````@jethrogb````
2022-06-25Rollup merge of #96412 - ChrisDenton:remove-dir-all, r=thomccMatthias Krüger-75/+81
Windows: Iterative `remove_dir_all` This will allow better strategies for use of memory and File handles. However, fully taking advantage of that is left to future work. Note to reviewer: It's probably best to view the `remove_dir_all_recursive` as a new function. The diff is not very helpful (imho).
2022-06-25Auto merge of #96820 - r-raymond:master, r=cuviperbors-5/+37
Make RwLockReadGuard covariant Hi, first time contributor here, if anything is not as expected, please let me know. `RwLockReadGoard`'s type constructor is invariant. Since it behaves like a smart pointer to an immutable reference, there is no reason that it should not be covariant. Take e.g. ``` fn test_read_guard_covariance() { fn do_stuff<'a>(_: RwLockReadGuard<'_, &'a i32>, _: &'a i32) {} let j: i32 = 5; let lock = RwLock::new(&j); { let i = 6; do_stuff(lock.read().unwrap(), &i); } drop(lock); } ``` where the compiler complains that &i doesn't live long enough. If `RwLockReadGuard` is covariant, then the above code is accepted because the lifetime can be shorter than `'a`. In order for `RwLockReadGuard` to be covariant, it can't contain a full reference to the `RwLock`, which can never be covariant (because it exposes a mutable reference to the underlying data structure). By reducing the data structure to the required pieces of `RwLock`, the rest falls in place. If there is a better way to do a test that tests successful compilation, please let me know. Fixes #80392
2022-06-24scan mountinfo when hardcoded cgroupv1 mountpoints don't workThe 8472-19/+83
2022-06-23Rollup merge of #96173 - jmaargh:jmaargh/with-capacity-doc-fix, r=Dylan-DPCMichael Goulet-37/+53
Fix documentation for `with_capacity` and `reserve` families of methods Fixes #95614 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.
2022-06-23Remove invalid doc comment on the size of an IP structLinus Färnstrand-9/+0
2022-06-23Remove `is_known_utf8` checks from more tests where it's no longer set.Dan Gohman-4/+0
2022-06-23Don't eagerly scan for `is_known_utf8` in `to_ascii_lowercase`/`uppercase`.Dan Gohman-12/+2
2022-06-23Panic safety.Dan Gohman-7/+7
2022-06-23Optimize `Wtf8Buf::into_string` for the case where it contains UTF-8.Dan Gohman-39/+366
Add a `is_known_utf8` flag to `Wtf8Buf`, which tracks whether the string is known to contain UTF-8. This is efficiently computed in many common situations, such as when a `Wtf8Buf` is constructed from a `String` or `&str`, or with `Wtf8Buf::from_wide` which is already doing UTF-16 decoding and already checking for surrogates. This makes `OsString::into_string` O(1) rather than O(N) on Windows in common cases. And, it eliminates the need to scan through the string for surrogates in `Args::next` and `Vars::next`, because the strings are already being translated with `Wtf8Buf::from_wide`. Many things on Windows construct `OsString`s with `Wtf8Buf::from_wide`, such as `DirEntry::file_name` and `fs::read_link`, so with this patch, users of those functions can subsequently call `.into_string()` without paying for an extra scan through the string for surrogates.
2022-06-23Assign issue number to the new const_socketaddrLinus Färnstrand-3/+3
2022-06-23Add IP structural_match testsLinus Färnstrand-0/+23
2022-06-23Remove ntohs/htons in favor of to_be/from_beLinus Färnstrand-14/+5
2022-06-23Implement IpV{4,6}Addr structs with native Rust encodingLinus Färnstrand-114/+41
2022-06-23Represent SocketAddrV4 and SocketAddrV6 as Rust native encodingLinus Färnstrand-105/+100
2022-06-23add tracking issue for exclusiveGus Wynn-1/+1
2022-06-23Use `unwrap` instead of `unwrap_unchecked`Jiahao XU-3/+7
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-22std: reimplement SGX thread joining to use `Parker`joboet-12/+9
2022-06-22std: rewrite SGX thread parkerjoboet-0/+96
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