about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2021-11-09optimize Hash for PathThe8472-2/+28
Hashing does not have to use the whole Components parsing machinery because we only need it to match the normalizations that Components does. * stripping redundant separators -> skipping separators * stripping redundant '.' directories -> skipping '.' following after a separator That's all it takes. And instead of hashing individual slices for each component we feed the bytes directly into the hasher which avoids hashing the length of each component in addition to its contents.
2021-11-09add benchmarks and tests for Hash and Eq impls on PathThe8472-2/+78
The tests check for consistency between Ord, Eq and Hash
2021-11-09Stabilize File::options()Jubilee Young-5/+4
Renames File::with_options to File::options, per consensus in rust-lang/rust#65439, and stabilizes it.
2021-11-08kmc-solid: Avoid the use of `asm_const`Tomoaki Kawada-7/+6
2021-11-07Auto merge of #89310 - joshtriplett:available-concurrency-affinity, r=m-ou-sebors-0/+8
Make `std::thread::available_concurrency` support process-limited number of CPUs Use `libc::sched_getaffinity` and count the number of CPUs in the returned mask. This handles cases where the process doesn't have access to all CPUs, such as when limited via `taskset` or similar. This also covers cgroup cpusets.
2021-11-06Stabilize `const_raw_ptr_deref` for `*const T`Jacob Pratt-1/+2
This stabilizes dereferencing immutable raw pointers in const contexts. It does not stabilize `*mut T` dereferencing. This is placed behind the `const_raw_mut_ptr_deref` feature gate.
2021-11-06use matches!() macro in more placesMatthias Krüger-7/+2
2021-11-05Also note tool expectations of fork vs clone3Josh Stone-0/+2
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-11-05Update another comment on fork vs. clone3Josh Stone-2/+2
2021-11-05Only use `clone3` when needed for pidfdJosh Stone-7/+6
In #89522 we learned that `clone3` is interacting poorly with Gentoo's `sandbox` tool. We only need that for the unstable pidfd extensions, so otherwise avoid that and use a normal `fork`.
2021-11-05Add UnwindSafe to OnceMilo-0/+4
2021-11-04Auto merge of #90392 - solid-rs:fix-solid-support, r=Mark-Simulacrumbors-1/+1
kmc-solid: Fix SOLID target This PR is a follow-up for #86191 and necessary to make the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets actually usable. - Bumps `libc` to 0.2.106, which includes <https://github.com/rust-lang/libc/pull/2227>. - Applies the change made by #89324 to this target's target-specific code.
2021-11-02formattingDrMeepster-1/+1
2021-11-02fix change clobbered by rebaseDrMeepster-7/+23
2021-11-02implement review suggestionsDrMeepster-9/+31
2021-11-02Update library/std/src/sys/unsupported/fs.rsDrMeepster-1/+1
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-11-02add read_buf for &FileDrMeepster-0/+4
2021-11-02fix test failure from trying to assume_init too muchDrMeepster-1/+1
2021-11-02add safety commentsDrMeepster-0/+2
2021-11-02Don't reinitialize hereDrMeepster-1/+8
2021-11-02more efficent File::read_buf impl for windows and unixDrMeepster-12/+93
2021-11-02consolidate 2 unsafe blocks into 1DrMeepster-2/+2
2021-11-02read_bufDrMeepster-296/+774
2021-11-03Auto merge of #90421 - ↵bors-1/+8
thomcc:friendship-ended-with-ssize_t-now-ptrdiff_t-is-my-best-friend, r=joshtriplett Replace `std::os::raw::c_ssize_t` with `std::os::raw::c_ptrdiff_t` The discussions in #88345 brought up that `ssize_t` is not actually the signed index type defined in stddef.h, but instead it's `ptrdiff_t`. It seems pretty clear that the use of `ssize_t` here was a mistake on my part, and that if we're going to bother having a isize-alike for FFI in `std::os::raw`, it should be `ptrdiff_t` and not `ssize_t`. Anyway, both this and `c_size_t` are dubious in the face of the discussion in https://internals.rust-lang.org/t/pre-rfc-usize-is-not-size-t/15369, and any RFC/project-group/etc that handles those issues there should contend with these types in some manner, but that doesn't mean we shouldn't fix something wrong like this, even if it is unstable. All that said, `size_t` is *vastly* more common in function signatures than either `ssize_t` or `ptrdiff_t`, so I'm going to update the tracking issue's list of unresolved questions to note that perhaps we only want `c_size_t` — I mostly added the signed version for symmetry, rather than to meet a need. (Given this, I'm also fine with modifying this patch to instead remove `c_ssize_t` without a replacement) CC `@magicant` (who brought the issue up) CC `@chorman0773` (who has a significantly firmer grasp on the minutae of the C standard than I do) r? `@joshtriplett` (original reviewer, active in the discussions around this)
2021-11-02Auto merge of #90442 - ChrisDenton:win-tls-dtor, r=alexcrichtonbors-1/+27
Windows thread-local keyless drop `#[thread_local]` allows us to maintain a per-thread list of destructors. This also avoids the need to synchronize global data (which is particularly tricky within the TLS callback function). r? `@alexcrichton`
2021-11-02Auto merge of #90439 - m-ou-se:thread-is-running, r=Mark-Simulacrumbors-1/+44
Add JoinHandle::is_running. This adds: ```rust impl<T> JoinHandle<T> { /// Checks if the the associated thread is still running its main function. /// /// This might return `false` for a brief moment after the thread's main /// function has returned, but before the thread itself has stopped running. pub fn is_running(&self) -> bool; } ``` The usual way to check if a background thread is still running is to set some atomic flag at the end of its main function. We already do that, in the form of dropping an Arc which will reduce the reference counter. So we might as well expose that information. This is useful in applications with a main loop (e.g. a game, gui, control system, ..) where you spawn some background task, and check every frame/iteration whether the background task is finished to .join() it in that frame/iteration while keeping the program responsive.
2021-11-01Run destructors from existing tls callbackChris Denton-23/+14
2021-11-01Add tracking issue for thread_is_running.Mara Bos-1/+1
2021-11-01itron: Rename `itron::thread::{available_conccurrency -> available_parallelism}`Tomoaki Kawada-1/+1
Catching up with commit b4615b5bf9e3e722b480190714ad44ecd7fa2ed1
2021-10-31Re-add `std::os::raw::c_ssize_t`, with more accurate documentationThom Chiovoloni-0/+7
2021-10-31 Windows: Resolve Command program without using the current directoryChris Denton-29/+216
2021-10-31Windows thread-local keyless dropChris Denton-1/+36
`#[thread_local]` allows us to maintain a per-thread list of destructors. This also avoids the need to synchronize global data (which is particularly tricky within the TLS callback function).
2021-10-31Add test for JoinHandle::is_running.Mara Bos-1/+35
2021-10-31Add JoinHandle::is_running.Mara Bos-0/+9
2021-10-31Rollup merge of #90431 - jkugelman:must-use-std-o-through-z, r=joshtriplettMatthias Krüger-2/+57
Add #[must_use] to remaining std functions (O-Z) I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is half of the remaining items from the `std` crate, from O-Z. `panicking::take_hook` has a side effect: it unregisters the current panic hook, returning it. I almost ignored it, but the documentation example shows `let _ = panic::take_hook();`, so following suit I went ahead and added a `#[must_use]`. ```rust std::panicking fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>; ``` I added these functions that clippy did not flag: ```rust std::path::Path fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool; std::path::Path fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool; std::path::Path fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> PathBuf; std::path::Path fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf; ``` Parent issue: #89692 r? `@joshtriplett`
2021-10-31Rollup merge of #90430 - jkugelman:must-use-std-a-through-n, r=joshtriplettMatthias Krüger-0/+54
Add #[must_use] to remaining std functions (A-N) I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is half of the remaining items from the `std` crate, from A-N. I added these functions myself. Clippy predictably ignored the `mut` ones, but I don't know why the rest weren't flagged. Check them closely, please? Maybe I overlooked good reasons. ```rust std::backtrace::Backtrace const fn disabled() -> Backtrace; std::backtrace::Backtrace<'a> fn frames(&'a self) -> &'a [BacktraceFrame]; std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn key_mut(&mut self) -> &mut K; std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn get_mut(&mut self) -> &mut V; std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn get_key_value(&mut self) -> (&K, &V); std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn get_key_value_mut(&mut self) -> (&mut K, &mut V); std::env fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString>; std::env fn split_paths<T: AsRef<OsStr> + ?Sized>(unparsed: &T) -> SplitPaths<'_>; std::io::Error fn get_mut(&mut self) -> Option<&mut (dyn error::Error + Send + Sync + 'static)>; ``` Parent issue: #89692 r? `@joshtriplett`
2021-10-31Rollup merge of #89786 - jkugelman:must-use-len-and-is_empty, r=joshtriplettMatthias Krüger-0/+5
Add #[must_use] to len and is_empty Parent issue: #89692 r? `@joshtriplett`
2021-10-31Rollup merge of #89068 - bjorn3:restructure_rt2, r=joshtriplettMatthias Krüger-15/+12
Restructure std::rt (part 2) A couple more cleanups on top of https://github.com/rust-lang/rust/pull/89011 Blocked on #89011
2021-10-31Rollup merge of #89835 - jkugelman:must-use-expensive-computations, ↵Matthias Krüger-0/+10
r=joshtriplett Add #[must_use] to expensive computations The unifying theme for this commit is weak, admittedly. I put together a list of "expensive" functions when I originally proposed this whole effort, but nobody's cared about that criterion. Still, it's a decent way to bite off a not-too-big chunk of work. Given the grab bag nature of this commit, the messages I used vary quite a bit. I'm open to wording changes. For some reason clippy flagged four `BTreeSet` methods but didn't say boo about equivalent ones on `HashSet`. I stared at them for a while but I can't figure out the difference so I added the `HashSet` ones in. ```rust // Flagged by clippy. alloc::collections::btree_set::BTreeSet<T> fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, T>; alloc::collections::btree_set::BTreeSet<T> fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet<T>) -> SymmetricDifference<'a, T> alloc::collections::btree_set::BTreeSet<T> fn intersection<'a>(&'a self, other: &'a BTreeSet<T>) -> Intersection<'a, T>; alloc::collections::btree_set::BTreeSet<T> fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> Union<'a, T>; // Ignored by clippy, but not by me. std::collections::HashSet<T, S> fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S>; std::collections::HashSet<T, S> fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T, S>) -> SymmetricDifference<'a, T, S> std::collections::HashSet<T, S> fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S>; std::collections::HashSet<T, S> fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S>; ``` Parent issue: #89692 r? ```@joshtriplett```
2021-10-31Rollup merge of #89677 - maxwase:is-symlink-stabilization, r=joshtriplettMatthias Krüger-5/+9
Stabilize `is_symlink()` for `Metadata` and `Path` I'm not fully sure about `since` version, correct me if I'm wrong Needs update after stabilization: [cargo-test-support](https://github.com/rust-lang/cargo/blob/8063672238a5b6c3a901c0fc17f3164692d0be85/crates/cargo-test-support/src/paths.rs#L202) Linked issue: #85748
2021-10-30Add #[must_use] to remaining std functions (A-N)John Kugelman-0/+54
2021-10-30Add #[must_use] to remaining std functions (O-Z)John Kugelman-2/+57
2021-10-31Make std::thread::available_concurrency support process-limited number of CPUsJosh Triplett-0/+8
Use libc::sched_getaffinity and count the number of CPUs in the returned mask. This handles cases where the process doesn't have access to all CPUs, such as when limited via taskset or similar.
2021-10-30Add #[must_use] to len and is_emptyJohn Kugelman-0/+5
2021-10-31Rollup merge of #90401 - mkroening:hermit-condvar, r=joshtriplettMatthias Krüger-2/+14
hermit: Implement Condvar::wait_timeout This implements `Condvar::wait_timeout` for the `hermit` target. See * https://github.com/hermitcore/rust/pull/2 * https://github.com/hermitcore/rust/pull/5 CC: `@stlankes`
2021-10-31Rollup merge of #89789 - jkugelman:must-use-thread-builder, r=joshtriplettMatthias Krüger-0/+1
Add #[must_use] to thread::Builder I copied the wording of the [`fmt::Debug` builders](https://doc.rust-lang.org/src/core/fmt/builders.rs.html#444). Affects: ```rust std/src/thread/mod.rs:289:5 std::thread::Builder fn new() -> Builder; std/src/thread/mod.rs:318:5 std::thread::Builder fn name(mut self, name: String) -> Builder; std/src/thread/mod.rs:341:5 std::thread::Builder fn stack_size(mut self, size: usize) -> Builder; ``` Parent issue: #89692 r? `@joshtriplett`
2021-10-30Replace `std::os::raw::c_ssize_t` with `std::os::raw::c_ptrdiff_t`Thom Chiovoloni-2/+2
2021-10-30Use "rustc" for testing Command argsChris Denton-3/+3
"echo" is not an application on Windows so `Command` tests could fail even if that's not what's being tested for.
2021-10-30Auto merge of #89174 - ChrisDenton:automatic-verbatim-paths, r=dtolnaybors-13/+203
Automatically convert paths to verbatim for filesystem operations that support it This allows using longer paths without the user needing to `canonicalize` or manually prefix paths. If the path is already verbatim then this has no effect. Fixes: #32689
2021-10-29hermit: Implement Condvar::wait_timeoutMartin Kröning-2/+14