about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2021-08-31disable `tcp_linger` feature in `std`Ibraheem Ahmed-1/+0
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-08-31Rollup merge of #88465 - marcospb19:master, r=joshtriplettMara Bos-6/+25
Adding examples to docs of `std::time` module And adding missing link to `Duration` from `Instant`.
2021-08-31Rollup merge of #88394 - ChrisDenton:patch-1, r=joshtriplettMara Bos-0/+3
Document `std::env::current_exe` possible rename behaviour It might not be obvious that the "path of the current running executable" may (or may not) imply "at the time it was loaded". This came up recently in chat so I thought it might be worth documenting.
2021-08-30Remove unnecessary `mut` from udp doctestsSönke Hahn-1/+1
2021-08-30clean up `c::linger` conversionibraheemdev-2/+2
2021-08-30add `TcpStream::set_linger` and `TcpStream::linger`ibraheemdev-1/+166
2021-08-29Adding examples to docs of std::time moduleJoão M. Bezerra-6/+25
And adding missing link to Duration from Instant
2021-08-29Add links in docs for some primitive typespatrick-gu-29/+38
2021-08-29Rollup merge of #88381 - rtzoeller:dfly_stack_t_ss_sp_void, r=dtolnayGuillaume Gomez-14/+0
Handle stack_t.ss_sp type change for DragonFlyBSD stack_t.ss_sp is now c_void on DragonFlyBSD, like the rest of the BSDs. Changed in https://github.com/rust-lang/libc/commit/02922ef7504906589d02c2e4d97d1172fa247cc3.
2021-08-28Auto merge of #87921 - kellerkindt:master, r=kennytmbors-0/+4
Add Saturating type (based on Wrapping type) Tracking #87920 ### Unresolved Questions <!-- Include any open questions that need to be answered before the feature can be stabilised. --> - [x] ~`impl Div for Saturating<T>` falls back on inner integer division - which seems alright?~ - [x] add `saturating_div`? (to respect division by `-1`) - [x] There is no `::saturating_shl` and `::saturating_shr`. (How to) implement `Shl`, `ShlAssign`, `Shr` and `ShrAssign`? - [naively](3f7d2ce28f8cf4dec56bf65fa2e6da0cf329ec55) - [x] ~`saturating_neg` is only implemented on [signed integer types](https://doc.rust-lang.org/std/?search=saturating_n)~ - [x] Is the implementation copied over from the `Wrapping`-type correct for `Saturating`? - [x] `Saturating::rotate_left` - [x] `Saturating::rotate_right` - [x] `Not` - [x] `BitXorOr` and `BitXorOrAssign` - [x] `BitOr` and `BitOrAssign` - [x] `BitAnd` and `BitAndAssign` - [x] `Saturating::swap_bytes` - [x] `Saturating::reverse_bits`
2021-08-28std: Stabilize command_accessJade-15/+11
Tracking issue: #44434
2021-08-27Handle stack_t.ss_sp type change for DragonFlyBSDRyan Zoeller-14/+0
stack_t.ss_sp is now c_void on DragonFlyBSD, so the specialization is no longer needed. Changed in https://github.com/rust-lang/libc/commit/02922ef7504906589d02c2e4d97d1172fa247cc3.
2021-08-27Document `std::env::current_exe` rename behaviourChris Denton-0/+3
It might not be obvious that the "path of the current running executable" may (or may not) mean "at the time it was loaded".
2021-08-26Add TcpListener::into_incoming and IntoIncomingpiegames-0/+51
The `incoming` method is really useful, however for some use cases the borrow this introduces is needlessly restricting. Thus, an owned variant is added.
2021-08-26Rollup merge of #88340 - thomcc:c_size_t, r=joshtriplettManish Goregaokar-0/+14
Add `c_size_t` and `c_ssize_t` to `std::os::raw`. Apparently these aren't guaranteed to be the same, and are merely "always the same in practice" (see https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/.60usize.60.20vs.20.60size_t.60). This is a big footgun, but I suspect it can be alleviated if we expose this and start migrating people to it in advance of any platforms that ever have this as different. I'll file a tracking issue after this gets some traction.
2021-08-25Reference tracking issueThom Chiovoloni-2/+2
2021-08-25Add `c_size_t` and `c_ssize_t` to `std::os::raw`.Thom Chiovoloni-0/+14
2021-08-25Rollup merge of #88299 - ijackson:bufwriter, r=Mark-SimulacrumLéo Lanteri Thauvin-10/+8
Stabilise BufWriter::into_parts The FCP for this has already completed, in #80690. This was just blocked on #85901 (which changed the name), which is now merged. The original stabilisation MR was #84770 but that has a lot of noise in it, and I also accidentally deleted the branch while trying to tidy up. So here is a new MR. Sorry for the noise. Closes #80690
2021-08-25Rollup merge of #88298 - ijackson:errorkind-reorder, r=dtolnayLéo Lanteri Thauvin-22/+30
Errorkind reorder I was doing a bit more work in this area and the untidiness of these two orderings bothered me. The commit messages have the detailed rationale. For your convenience, I c&p them here: ``` io::ErrorKind: rationalise ordering in main enum It is useful to keep some coherent structure to this ordering. In particular, Other and Uncategorized should be next to each other, at the end. Also it seems to make sense to treat UnexpectedEof and OutOfMemory specially, since they are not like the other errors (despite OutOfMemory also being generatable by some OS errors). So: * Move Other to the end, just before Uncategorized * Move Unsupported to between Interrupted and UnexpectedEof * Add some comments documenting where to add things ``` ``` io::Error: alphabeticise the match in as_str() There was no rationale for the previous ordering. ``` r? kennytm since that's who rust-highfive picked before, in #88294 which I accidentally closed.
2021-08-24Manual Debug for Unix ExitCode ExitStatus ExitStatusErrorIan Jackson-3/+21
These structs have misleading names. An ExitStatus[Error] is actually a Unix wait status; an ExitCode is actually an exit status. The Display impls are fixed, but the Debug impls are still misleading, as reported in #74832. Fix this by pretending that these internal structs are called `unix_exit_status` and `unix_wait_status` as applicable. (We can't actually rename the structs because of the way that the cross-platform machinery works: the names are cross-platform.) Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24Stabilise unix_process_await_more, extra ExitStatusExt methodsIan Jackson-4/+4
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24Stabilise BufWriter::into_partsIan Jackson-10/+8
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24Fix tidyIan Jackson-2/+2
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24io::ErrorKind: rationalise ordering in main enumIan Jackson-17/+24
It is useful to keep some coherent structure to this ordering. In particular, Other and Uncategorized should be next to each other, at the end. Also it seems to make sense to treat UnexpectedEof and OutOfMemory specially, since they are not like the other errors (despite OutOfMemory also being generatable by some OS errors). So: * Move Other to the end, just before Uncategorized * Move Unsupported to between Interrupted and UnexpectedEof * Add some comments documenting where to add things Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24io::Error: alphabeticise the match in as_str()Ian Jackson-5/+6
There was no rationale for the previous ordering. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24Remove unnecessary unsafe block in `process_unix`Léo Lanteri Thauvin-2/+1
2021-08-24Fix typo “a Rc” → “an Rc”Frank Steffahn-2/+2
2021-08-23Rollup merge of #88230 - steffahn:a_an, r=oli-obkMara Bos-26/+26
Fix typos “a”→“an” Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an. While automation was used to find these, every change was checked manually. Changes in submodules get separate PRs: * https://github.com/rust-lang/stdarch/pull/1201 * https://github.com/rust-lang/cargo/pull/9821 * https://github.com/rust-lang/miri/pull/1874 * https://github.com/rust-lang/rls/pull/1746 * https://github.com/rust-analyzer/rust-analyzer/pull/9984 _folks @ rust-analyzer are fast at merging…_ * https://github.com/rust-analyzer/rust-analyzer/pull/9985 * https://github.com/rust-analyzer/rust-analyzer/pull/9987 * https://github.com/rust-analyzer/rust-analyzer/pull/9989 _For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._ <hr> This has some overlap with #88226, but neither is a strict superset of the other. If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.
2021-08-23Auto merge of #88220 - sunfishcode:sunfishcode/unix-listener-io-safety, ↵bors-1/+25
r=joshtriplett Implement `AsFd` etc. for `UnixListener`. Implement `AsFd`, `From<OwnedFd>`, and `Into<OwnedFd>` for `UnixListener`. This is a follow-up to #87329. r? `@joshtriplett`
2021-08-23Auto merge of #87598 - ccqpein:master, r=yaahcbors-2/+10
Add doctests for HashMap's into_values and into_keys methods Fixes #87591
2021-08-22Remove redundant conversions.Dan Gohman-2/+2
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-6/+6
same search
2021-08-22Fix more “a”/“an” typosFrank Steffahn-4/+4
2021-08-22Fix typos “a”→“an”Frank Steffahn-17/+17
2021-08-22Add doctests for 's into_values and into_keys methodsccQpein-2/+10
2021-08-22Auto merge of #85166 - mbhall88:file-prefix, r=dtolnaybors-90/+372
add file_prefix method to std::path This is an initial implementation of `std::path::Path::file_prefix`. It is effectively a "left" variant of the existing [`file_stem`](https://doc.rust-lang.org/std/path/struct.Path.html#method.file_stem) method. An illustration of the difference is ```rust use std::path::Path; let path = Path::new("foo.tar.gz"); assert_eq!(path.file_stem(), Some("foo.tar")); assert_eq!(path.file_prefix(), Some("foo")); ``` In my own development, I generally find I almost always want the prefix, rather than the stem, so I thought it might be best to suggest it's addition to libstd. Of course, as this is my first contribution, I expect there is probably more work that needs to be done. Additionally, if the libstd team feel this isn't appropriate then so be it. There has been some [discussion about this on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/file_lstem/near/238076313) and a user there suggested I open a PR to see whether someone in the libstd team thinks it is worth pursuing.
2021-08-21Implement `AsFd` etc. for `UnixListener`.Dan Gohman-1/+25
Implement `AsFd`, `From<OwnedFd>`, and `Into<OwnedFd>` for `UnixListener`. This is a follow-up to #87329.
2021-08-20Auto merge of #83093 - the8472:smaller-instant-hammer, r=Amanieubors-12/+215
where available use AtomicU{64,128} instead of mutex for Instant backsliding protection This decreases the overhead of backsliding protection on x86 systems with unreliable TSC, e.g. windows. And on aarch64 systems where 128bit atomics are available. The following benchmarks were taken on x86_64 linux though by overriding `actually_monotonic()`, the numbers may look different on other platforms ``` # actually_monotonic() == true test time::tests::instant_contention_01_threads ... bench: 44 ns/iter (+/- 0) test time::tests::instant_contention_02_threads ... bench: 44 ns/iter (+/- 0) test time::tests::instant_contention_04_threads ... bench: 44 ns/iter (+/- 0) test time::tests::instant_contention_08_threads ... bench: 44 ns/iter (+/- 0) test time::tests::instant_contention_16_threads ... bench: 44 ns/iter (+/- 0) # 1x AtomicU64 test time::tests::instant_contention_01_threads ... bench: 65 ns/iter (+/- 0) test time::tests::instant_contention_02_threads ... bench: 157 ns/iter (+/- 20) test time::tests::instant_contention_04_threads ... bench: 281 ns/iter (+/- 53) test time::tests::instant_contention_08_threads ... bench: 555 ns/iter (+/- 77) test time::tests::instant_contention_16_threads ... bench: 883 ns/iter (+/- 107) # mutex test time::tests::instant_contention_01_threads ... bench: 60 ns/iter (+/- 2) test time::tests::instant_contention_02_threads ... bench: 770 ns/iter (+/- 231) test time::tests::instant_contention_04_threads ... bench: 1,347 ns/iter (+/- 45) test time::tests::instant_contention_08_threads ... bench: 2,693 ns/iter (+/- 114) test time::tests::instant_contention_16_threads ... bench: 5,244 ns/iter (+/- 487) ``` Since I don't have an arm machine with 128bit atomics I wasn't able to benchmark the AtomicU128 implementation.
2021-08-20fix tests on wasm targets that have 32bit time_t and don't have threadsThe8472-2/+12
2021-08-20Auto merge of #87329 - sunfishcode:sunfishcode/io-safety, r=joshtriplettbors-711/+2229
I/O safety. Introduce `OwnedFd` and `BorrowedFd`, and the `AsFd` trait, and implementations of `AsFd`, `From<OwnedFd>` and `From<T> for OwnedFd` for relevant types, along with Windows counterparts for handles and sockets. Tracking issue: <https://github.com/rust-lang/rust/issues/87074> RFC: <https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md> Highlights: - The doc comments at the top of library/std/src/os/unix/io/mod.rs and library/std/src/os/windows/io/mod.rs - The new types and traits in library/std/src/os/unix/io/fd.rs and library/std/src/os/windows/io/handle.rs - The removal of the `RawHandle` struct the Windows impl, which had the same name as the `RawHandle` type alias, and its functionality is now folded into `Handle`. Managing five levels of wrapping (File wraps sys::fs::File wraps sys::fs::FileDesc wraps OwnedFd wraps RawFd, etc.) made for a fair amount of churn and verbose as/into/from sequences in some places. I've managed to simplify some of them, but I'm open to ideas here. r? `@joshtriplett`
2021-08-20Auto merge of #86898 - the8472:path-cmp, r=dtolnaybors-7/+108
Add fast path for Path::cmp that skips over long shared prefixes ``` # before test path::tests::bench_path_cmp_fast_path_buf_sort ... bench: 60,811 ns/iter (+/- 865) test path::tests::bench_path_cmp_fast_path_long ... bench: 6,459 ns/iter (+/- 275) test path::tests::bench_path_cmp_fast_path_short ... bench: 1,777 ns/iter (+/- 34) # after test path::tests::bench_path_cmp_fast_path_buf_sort ... bench: 38,140 ns/iter (+/- 211) test path::tests::bench_path_cmp_fast_path_long ... bench: 1,471 ns/iter (+/- 24) test path::tests::bench_path_cmp_fast_path_short ... bench: 1,106 ns/iter (+/- 9) ```
2021-08-19Stabilize std::os::unix::fs::chrootJosh Triplett-2/+1
2021-08-19Fix doc test failures on Windows.Dan Gohman-1/+7
2021-08-19Factor out a common `RawFd`/`AsRawFd`/etc for Unix and WASI.Dan Gohman-525/+355
2021-08-19Fix syntax for non-doc comments, and use `crate::` instead of `std::`.Dan Gohman-6/+6
2021-08-19Add I/O safety trait impls for process::Stdio and process::Child.Dan Gohman-2/+36
2021-08-19Use the correct `into_*` on Windows to avoid dropping a stdio handle.Dan Gohman-2/+2
Use `into_raw_handle()` rather than `into_inner()` to completely consume a `Handle` without dropping its contained handle.
2021-08-19Remove the `#![feature(io_safety)]` from lib.rs.Dan Gohman-1/+0
2021-08-19Fix an unused import warning.Dan Gohman-1/+1
2021-08-19Update PidFd for the new I/O safety APIs.Dan Gohman-9/+33