about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-07-05Add comment and simplify `hiberfil_sys` testChris Denton-5/+6
2022-07-05Windows: Use `FindFirstFileW` if `metadata` failsChris Denton-10/+72
Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory.
2022-07-05`impl From<c::WIN32_FIND_DATAW> for FileAttr`Chris Denton-16/+21
2022-07-05Rollup merge of #97300 - ChayimFriedman2:patch-1, r=dtolnayDylan DPC-0/+7
Implement `FusedIterator` for `std::net::[Into]Incoming` They never return `None`, so they trivially fulfill the contract. What should I put for the stability attribute of `Incoming`?
2022-07-03Auto merge of #97437 - jyn514:impl-asrawfd-arc, r=dtolnaybors-0/+62
`impl<T: AsRawFd> AsRawFd for {Arc,Box}<T>` 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() } } ``` In particular, this leads to lots of "multiple applicable items in scope" errors because you have to disambiguate `MyTrait::as_raw_fd` from `AsRawFd::as_raw_fd` at each call site. In generic contexts, when passing the type to a function that takes `impl AsRawFd` it's also sometimes required to use `T: MyTrait + AsRawFd`, which wouldn't be necessary if I could write `MyTrait: AsRawFd`. After this PR, the code can be simpler: ```rust trait MyTrait: AsRawFd {} impl<T: MyTrait> MyTrait for Arc<T> {} ```
2022-07-03Auto merge of #98673 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrumbors-4/+3
Bump bootstrap compiler r? `@Mark-Simulacrum`
2022-07-02Bump std::net::Incoming FusedIterator impl to Rust 1.64David Tolnay-1/+1
2022-07-02Auto merge of #97235 - nbdd0121:unwind, r=Amanieubors-0/+2
Fix FFI-unwind unsoundness with mixed panic mode UB maybe introduced when an FFI exception happens in a `C-unwind` foreign function and it propagates through a crate compiled with `-C panic=unwind` into a crate compiled with `-C panic=abort` (#96926). To prevent this unsoundness from happening, we will disallow a crate compiled with `-C panic=unwind` to be linked into `panic-abort` *if* it contains a call to `C-unwind` foreign function or function pointer. If no such call exists, then we continue to allow such mixed panic mode linking because it's sound (and stable). In fact we still need the ability to do mixed panic mode linking for std, because we only compile std once with `-C panic=unwind` and link it regardless panic strategy. For libraries that wish to remain compile-once-and-linkable-to-both-panic-runtimes, a `ffi_unwind_calls` lint is added (gated under `c_unwind` feature gate) to flag any FFI unwind calls that will cause the linkable panic runtime be restricted. In summary: ```rust #![warn(ffi_unwind_calls)] mod foo { #[no_mangle] pub extern "C-unwind" fn foo() {} } extern "C-unwind" { fn foo(); } fn main() { // Call to Rust function is fine regardless ABI. foo::foo(); // Call to foreign function, will cause the crate to be unlinkable to panic-abort if compiled with `-Cpanic=unwind`. unsafe { foo(); } //~^ WARNING call to foreign function with FFI-unwind ABI let ptr: extern "C-unwind" fn() = foo::foo; // Call to function pointer, will cause the crate to be unlinkable to panic-abort if compiled with `-Cpanic=unwind`. ptr(); //~^ WARNING call to function pointer with FFI-unwind ABI } ``` Fix #96926 `@rustbot` label: T-compiler F-c_unwind
2022-07-01Adjust for rustfmt order changeMark Rousskov-1/+1
2022-07-01update cfg(bootstrap)sPietro Albini-3/+2
2022-06-30Rollup merge of #98503 - RalfJung:scope-race, r=m-ou-seMatthias Krüger-10/+17
fix data race in thread::scope Puts the `ScopeData` into an `Arc` so it sticks around as long as we need it. This means one extra `Arc::clone` per spawned scoped thread, which I hope is fine. Fixes https://github.com/rust-lang/rust/issues/98498 r? `````@m-ou-se`````
2022-06-30Rollup merge of #97629 - guswynn:exclusive_struct, r=m-ou-seMatthias Krüger-0/+3
[core] add `Exclusive` to sync (discussed here: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Adding.20.60SyncWrapper.60.20to.20std) `Exclusive` is a wrapper that exclusively allows mutable access to the inner value if you have exclusive access to the wrapper. It acts like a compile time mutex, and hold an unconditional `Sync` implementation. ## Justification for inclusion into std - This wrapper unblocks actual problems: - The example that I hit was a vector of `futures::future::BoxFuture`'s causing a central struct in a script to be non-`Sync`. To work around it, you either write really difficult code, or wrap the futures in a needless mutex. - Easy to maintain: this struct is as simple as a wrapper can get, and its `Sync` implementation has very clear reasoning - Fills a gap: `&/&mut` are to `RwLock` as `Exclusive` is to `Mutex` ## Public Api ```rust // core::sync #[derive(Default)] struct Exclusive<T: ?Sized> { ... } impl<T: ?Sized> Sync for Exclusive {} impl<T> Exclusive<T> { pub const fn new(t: T) -> Self; pub const fn into_inner(self) -> T; } impl<T: ?Sized> Exclusive<T> { pub const fn get_mut(&mut self) -> &mut T; pub const fn get_pin_mut(Pin<&mut self>) -> Pin<&mut T>; pub const fn from_mut(&mut T) -> &mut Exclusive<T>; pub const fn from_pin_mut(Pin<&mut T>) -> Pin<&mut Exclusive<T>>; } impl<T: Future> Future for Exclusive { ... } impl<T> From<T> for Exclusive<T> { ... } impl<T: ?Sized> Debug for Exclusive { ... } ``` ## Naming This is a big bikeshed, but I felt that `Exclusive` captured its general purpose quite well. ## Stability and location As this is so simple, it can be in `core`. I feel that it can be stabilized quite soon after it is merged, if the libs teams feels its reasonable to add. Also, I don't really know how unstable feature work in std/core's codebases, so I might need help fixing them ## Tips for review The docs probably are the thing that needs to be reviewed! I tried my best, but I'm sure people have more experience than me writing docs for `Core` ### Implementation: The API is mostly pulled from https://docs.rs/sync_wrapper/latest/sync_wrapper/struct.SyncWrapper.html (which is apache 2.0 licenesed), and the implementation is trivial: - its an unsafe justification for pinning - its an unsafe justification for the `Sync` impl (mostly reasoned about by ````@danielhenrymantilla```` here: https://github.com/Actyx/sync_wrapper/pull/2) - and forwarding impls, starting with derivable ones and `Future`
2022-06-30std: use futex-based locks on Fuchsiajoboet-64/+246
2022-06-28Follow C-RW-VALUE in std::io::Cursor exampleMatt Fellenz-1/+1
2022-06-28Rollup merge of #98617 - ChrisDenton:const-unwrap, r=Mark-SimulacrumMatthias Krüger-5/+15
Remove feature `const_option` from std This is part of the effort to reduce the number of unstable features used by std. This one is easy as it's only used in one place.
2022-06-28Add a fixme commentChris Denton-0/+3
2022-06-28Remove feature `const_option` from stdChris Denton-5/+12
2022-06-28Rollup merge of #98555 - mkroening:hermit-lock-init, r=m-ou-seDylan DPC-9/+25
Hermit: Fix initializing lazy locks Closes https://github.com/hermitcore/rusty-hermit/issues/322. The initialization function of hermit's `Condvar` is not called since https://github.com/rust-lang/rust/pull/97647 and was erroneously removed in https://github.com/rust-lang/rust/pull/97879. r? ``@m-ou-se`` CC: ``@stlankes``
2022-06-28Auto merge of #98324 - conradludgate:write-vectored-vec, r=Mark-Simulacrumbors-25/+149
attempt to optimise vectored write benchmarked: old: ``` test io::cursor::tests::bench_write_vec ... bench: 68 ns/iter (+/- 2) test io::cursor::tests::bench_write_vec_vectored ... bench: 913 ns/iter (+/- 31) ``` new: ``` test io::cursor::tests::bench_write_vec ... bench: 64 ns/iter (+/- 0) test io::cursor::tests::bench_write_vec_vectored ... bench: 747 ns/iter (+/- 27) ``` More unsafe than I wanted (and less gains) in the end, but it still does the job
2022-06-27fix data race in thread::scopeRalf Jung-10/+17
2022-06-27Seal Windows `FileTypeExt` extension trait to allow adding future methodsJosh Triplett-1/+5
2022-06-27Stabilize Windows `FileTypeExt` with `is_symlink_dir` and `is_symlink_file`Josh Triplett-4/+4
These calls allow detecting whether a symlink is a file or a directory, a distinction Windows maintains, and one important to software that wants to do further operations on the symlink (e.g. removing it).
2022-06-27make Condvar, Mutex, RwLock const constructors work with unsupported implJorge Aparicio-0/+7
2022-06-26Hermit: Make Mutex::init a no-opMartin Kröning-3/+1
2022-06-26Hermit: Fix initializing lazy locksMartin Kröning-6/+24
2022-06-26Rollup merge of #98541 - Veykril:patch-2, r=Dylan-DPCMatthias Krüger-1/+1
Update `std::alloc::System` doc example code style `return` on the last line of a block is unidiomatic so I don't think the example should be using that here
2022-06-26Rollup merge of #97140 - joboet:solid_parker, r=m-ou-seMatthias Krüger-6/+225
std: use an event-flag-based thread parker on SOLID `Mutex` and `Condvar` are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore, the generic `Parker` needs to be replaced on all platforms where the new lock implementation will be used, which, after #96393, are SOLID, SGX and Hermit (more PRs coming soon). SOLID, conforming to the [μITRON specification](http://www.ertl.jp/ITRON/SPEC/FILE/mitron-400e.pdf), has event flags, which are a thread parking primitive very similar to `Parker`. However, they do not make any atomic ordering guarantees (even though those can probably be assumed) and necessitate a system call even when the thread token is already available. Hence, this `Parker`, like the Windows parker, uses an extra atomic state variable. I future-proofed the code by wrapping the event flag in a `WaitFlag` structure, as both SGX and Hermit can share the Parker implementation, they just have slightly different primitives (SGX uses signals and Hermit has a thread blocking API). `````@kawadakk````` I assume you are the target maintainer? Could you test this for me?
2022-06-26attempt to optimise vectored writeConrad Ludgate-25/+149
2022-06-26Update `std::alloc::System` docsLukas Wirth-1/+1
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