about summary refs log tree commit diff
path: root/library/std
AgeCommit message (Collapse)AuthorLines
2021-07-24Rollup merge of #86790 - janikrabe:retain-iter-order-doc, r=m-ou-seYuki Okushi-0/+2
Document iteration order of `retain` functions For `HashSet` and `HashMap`, this simply copies the comment from `BinaryHeap::retain`. For `BTreeSet` and `BTreeMap`, this adds an additional guarantee that wasn't previously documented. I think that because these data structures are inherently ordered and other functions guarantee ordered iteration, it makes sense to provide this guarantee for `retain` as well.
2021-07-23Stabilize core::task::ready!Yoshua Wuyts-1/+0
2021-07-22Remove Option from BufWriterAlex Macleod-10/+14
Fixes #72925
2021-07-21VxWorks does provide sigemptyset and sigaddsetNicholas Baron-1/+1
2021-07-21Disable glibc tests on vxworksNicholas Baron-0/+2
VxWorks does not provide glibc, but we still need to test rustc on VxWorks.
2021-07-21Rollup merge of #87279 - sunfishcode:document-unix-argv, r=RalfJungGuillaume Gomez-2/+16
Add comments explaining the unix command-line argument support. Following up on #87236, add comments to the unix command-line argument support explaining that the code doesn't mutate the system-provided argc/argv, and that this is why the code doesn't need a lock or special memory ordering. r? ```@RalfJung```
2021-07-21Add tracking issue and link to man-pageDominik Stolz-3/+4
2021-07-21Add PidFd type and seal traitsDominik Stolz-110/+279
Improve docs Split do_fork into two Make do_fork unsafe Add target attribute to create_pidfd field in Command Add method to get create_pidfd value
2021-07-21Typo fixJosh Triplett-1/+1
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
2021-07-21Add Linux-specific pidfd process extensionsAaron Hill-7/+159
Background: Over the last year, pidfd support was added to the Linux kernel. This allows interacting with other processes. In particular, this allows waiting on a child process with a timeout in a race-free way, bypassing all of the awful signal-handler tricks that are usually required. Pidfds can be obtained for a child process (as well as any other process) via the `pidfd_open` syscall. Unfortunately, this requires several conditions to hold in order to be race-free (i.e. the pid is not reused). Per `man pidfd_open`: ``` · the disposition of SIGCHLD has not been explicitly set to SIG_IGN (see sigaction(2)); · the SA_NOCLDWAIT flag was not specified while establishing a han‐ dler for SIGCHLD or while setting the disposition of that signal to SIG_DFL (see sigaction(2)); and · the zombie process was not reaped elsewhere in the program (e.g., either by an asynchronously executed signal handler or by wait(2) or similar in another thread). If any of these conditions does not hold, then the child process (along with a PID file descriptor that refers to it) should instead be created using clone(2) with the CLONE_PIDFD flag. ``` Sadly, these conditions are impossible to guarantee once any libraries are used. For example, C code runnng in a different thread could call `wait()`, which is impossible to detect from Rust code trying to open a pidfd. While pid reuse issues should (hopefully) be rare in practice, we can do better. By passing the `CLONE_PIDFD` flag to `clone()` or `clone3()`, we can obtain a pidfd for the child process in a guaranteed race-free manner. This PR: This PR adds Linux-specific process extension methods to allow obtaining pidfds for processes spawned via the standard `Command` API. Other than being made available to user code, the standard library does not make use of these pidfds in any way. In particular, the implementation of `Child::wait` is completely unchanged. Two Linux-specific helper methods are added: `CommandExt::create_pidfd` and `ChildExt::pidfd`. These methods are intended to serve as a building block for libraries to build higher-level abstractions - in particular, waiting on a process with a timeout. I've included a basic test, which verifies that pidfds are created iff the `create_pidfd` method is used. This test is somewhat special - it should always succeed on systems with the `clone3` system call available, and always fail on systems without `clone3` available. I'm not sure how to best ensure this programatically. This PR relies on the newer `clone3` system call to pass the `CLONE_FD`, rather than the older `clone` system call. `clone3` was added to Linux in the same release as pidfds, so this shouldn't unnecessarily limit the kernel versions that this code supports. Unresolved questions: * What should the name of the feature gate be for these newly added methods? * Should the `pidfd` method distinguish between an error occurring and `create_pidfd` not being called?
2021-07-21Auto merge of #86847 - tlyu:stdin-forwarders, r=joshtriplettbors-1/+44
add `Stdin::lines`, `Stdin::split` forwarder methods Add forwarder methods `Stdin::lines` and `Stdin::split`, which consume and lock a `Stdin` handle, and forward on to the corresponding `BufRead` methods. This should make it easier for beginners to use those iterator constructors without explicitly dealing with locks or lifetimes. Replaces #86412. ~~Based on #86846 to get the tracking issue number for the `stdio_locked` feature.~~ Rebased after merge, so it's only one commit now. r? `@joshtriplett` `@rustbot` label +A-io +C-enhancement +D-newcomer-roadblock +T-libs-api
2021-07-20Use hashbrown's `extend_reserve()` in `HashMap`inquisitivecrystal-9/+1
2021-07-19Add comments explaining the unix command-line argument support.Dan Gohman-2/+16
Following up on #87236, add comments to the unix command-line argument support explaining that the code doesn't mutate the system-provided argc/argv, and that this is why the code doesn't need a lock or special memory ordering.
2021-07-19Rollup merge of #87236 - sunfishcode:avoid-locking-args, r=joshtriplettGuillaume Gomez-22/+3
Simplify command-line argument initialization on unix Simplify Rust's command-line argument initialization code on unix: - The cleanup code isn't needed, because it was just zeroing out non-owning variables at runtime cleanup time. After 91c3eee1735ad72b579f99cbb6919c3471747d94, Rust's command-line initialization code on unix no longer allocates `CString`s and a `Vec` at startup time. - The `Mutex` isn't needed; if there's somehow a call to `args()` before argument initialization has happened, the code returns return an empty list, which we can do with a null check. With these changes, a simple cdylib that doesn't use threads avoids getting `pthread_mutex_lock`/`pthread_mutex_unlock` in its symbol table.
2021-07-19Rollup merge of #87227 - bstrie:asm2arch, r=AmanieuGuillaume Gomez-7/+23
Move asm! and global_asm! to core::arch Follow-up to https://github.com/rust-lang/stdarch/pull/1183 . Implements the libs-api team decision from rust-lang/rust#84019 (comment) . In order to not break nightly users, this PR also adds the newly-moved items to the prelude. However, a decision will need to be made before stabilization as to whether these items should remain in the prelude. I will file an issue for this separately. Fixes #84019 . r? `@Amanieu`
2021-07-18Move asm! and global_asm! to core::archbstrie-7/+23
2021-07-18Rollup merge of #87170 - xFrednet:clippy-5393-add-diagnostic-items, ↵Yuki Okushi-0/+6
r=Manishearth,oli-obk Add diagnostic items for Clippy This adds a bunch of diagnostic items to `std`/`core`/`alloc` functions, structs and traits used in Clippy. The actual refactorings in Clippy to use these items will be done in a different PR in Clippy after the next sync. This PR doesn't include all paths Clippy uses, I've only gone through the first 85 lines of Clippy's [`paths.rs`](https://github.com/rust-lang/rust-clippy/blob/ecf85f4bdc319f9d9d853d1fff68a8a25e64c7a8/clippy_utils/src/paths.rs) (after rust-lang/rust-clippy#7466) to get some feedback early on. I've also decided against adding diagnostic items to methods, as it would be nicer and more scalable to access them in a nicer fashion, like adding a `is_diagnostic_assoc_item(did, sym::Iterator, sym::map)` function or something similar (Suggested by `@camsteffen` [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Diagnostic.20Item.20Naming.20Convention.3F/near/225024603)) There seems to be some different naming conventions when it comes to diagnostic items, some use UpperCamelCase (`BinaryHeap`) and some snake_case (`hashmap_type`). This PR uses UpperCamelCase for structs and traits and snake_case with the module name as a prefix for functions. Any feedback on is this welcome. cc: rust-lang/rust-clippy#5393 r? `@Manishearth`
2021-07-17x.py fmtDan Gohman-5/+1
2021-07-17Remove an unnecessary `Mutex` around argument initialization.Dan Gohman-8/+7
In the command-line argument initialization code, remove the Mutex around the `ARGV` and `ARGC` variables, and simply check whether ARGV is non-null before dereferencing it. This way, if either of ARGV or ARGC is not initialized, we'll get an empty argument list. This allows simple cdylibs to avoid having `pthread_mutex_lock`/`pthread_mutex_unlock` appear in their symbol tables if they don't otherwise use threads.
2021-07-17Remove args cleanup code.Dan Gohman-14/+0
As of 91c3eee1735ad72b579f99cbb6919c3471747d94, the global ARGC and ARGV no longer reference dynamically-allocated memory, so they don't need to be cleaned up.
2021-07-16rename assert_matches moduleJane Lusby-3/+3
2021-07-15Stabilize `into_parts()` and `into_error()`inquisitivecrystal-4/+2
2021-07-15Added diagnostic items to structs and traits for ClippyxFrednet-0/+6
2021-07-15Rollup merge of #87081 - a1phyr:add_wasi_ext_tracking_issue, r=dtolnayYuki Okushi-2/+2
Add tracking issue number to `wasi_ext` Feature `wasi_ext` is tracked by #71213 but is was not in the source code.
2021-07-15Rollup merge of #86947 - m-ou-se:assert-matches-to-submodule, r=yaahcYuki Okushi-2/+2
Move assert_matches to an inner module Fixes #82913
2021-07-13expand: Support helper attributes for built-in derive macrosVadim Petrochenkov-1/+2
2021-07-12add Stdin::lines, Stdin::split forwarder methodsTaylor Yu-1/+44
Add forwarder methods `Stdin::lines` and `Stdin::split`, which consume and lock a `Stdin` handle, and forward on to the corresponding `BufRead` methods. This should make it easier for beginners to use those iterator constructors without explicitly dealing with locks or lifetimes.
2021-07-13Rollup merge of #86846 - tlyu:stdio-locked-tracking, r=joshtriplettYuki Okushi-7/+7
stdio_locked: add tracking issue Add the tracking issue number #86845 to the stability attributes for the implementation in #86799. r? `@joshtriplett` `@rustbot` label +A-io +C-cleanup +T-libs-api
2021-07-13Rollup merge of #86811 - soerenmeier:remove_remaining, r=yaahcYuki Okushi-26/+0
Remove unstable `io::Cursor::remaining` Adding `io::Cursor::remaining` in #86037 caused a conflict with the implementation of `bytes::Buf` for `io::Cursor`, leading to an error in nightly, see https://github.com/rust-lang/rust/issues/86369#issuecomment-867723485. This fixes the error by temporarily removing the `remaining` function. r? `@yaahc`
2021-07-12Add tracking issue number to `wasi_ext`Benoît du Garreau-2/+2
2021-07-12Rollup merge of #86951 - cyberia-ng:fp-negative-zero-sqrt-docs, ↵Yuki Okushi-2/+6
r=Mark-Simulacrum [docs] Clarify behaviour of f64 and f32::sqrt when argument is negative zero From IEEE 754 section 6.3: > Except that squareRoot(−0) shall be −0, every numeric squareRoot result shall have a positive sign.
2021-07-11Add example with a bunch of leading zeosSmitty-0/+1
2021-07-11Simplify leading zero checksSmitty-5/+2
2021-07-10Auto merge of #85953 - inquisitivecrystal:weak-linkat-in-fs-hardlink, ↵bors-17/+91
r=joshtriplett Fix linker error Currently, `fs::hard_link` determines whether platforms have `linkat` based on the OS, and uses `link` if they don't. However, this heuristic does not work well if a platform provides `linkat` on newer versions but not on older ones. On old MacOS, this currently causes a linking error. This commit fixes `fs::hard_link` by telling it to use `weak!` on macOS. This means that, on that operating system, we now check for `linkat` at runtime and use `link` if it is not available. Fixes #80804. `@rustbot` label T-libs-impl
2021-07-10Make tests pass on old macosAris Merchant-0/+18
On old macos systems, `fs::hard_link()` will follow symlinks. This changes the test `symlink_hard_link` to exit early on these systems, so that tests can pass.
2021-07-10Change `weak!` and `linkat!` to macros 2.0Aris Merchant-4/+38
`weak!` is needed in a test in another module. With macros 1.0, importing `weak!` would require reordering module declarations in `std/src/lib.rs`, which is a bit too evil.
2021-07-11Rollup merge of #87011 - RalfJung:thread-id-supply-shortage, r=nagisaYuki Okushi-1/+2
avoid reentrant lock acquire when ThreadIds run out Discovered by `@bjorn3`
2021-07-10rename variableRalf Jung-2/+2
2021-07-10avoid reentrant lock acquire when ThreadIds run outRalf Jung-0/+1
2021-07-09Update docs for `fs::hard_link`Aris Merchant-2/+5
2021-07-09Fix linker errorAris Merchant-11/+30
This makes `fs::hard_link` use weak! for some platforms, thereby preventing a linker error.
2021-07-09Reject too-long IPs quickerSmitty-1/+6
Now that there can't be a bunch of leading zeros, parsing can be optimized a bit.
2021-07-09Clarify docs on what IPv4 octal addresses areSmitty-1/+4
The way octal literals are written in IP addresses differs from the way they are written in Rust code, so the way that octal/hex literals in IPs are written is explictly mentioned.
2021-07-09Debug formatting of raw_arg()Kornel-2/+6
2021-07-09Use AsRef in CommandExt for raw_argKornel-3/+3
2021-07-09Unescaped command-line arguments for WindowsKornel-19/+86
Fixes #29494
2021-07-09Test escaping of trialing slashes in Windows command-line argsKornel-0/+5
2021-07-08Disallow octal zeros in IPv4 addressesSmitty-9/+25
2021-07-08Rollup merge of #86726 - ↵Guillaume Gomez-2/+2
sexxi-goose:use-diagnostic-item-for-rfc2229-migration, r=nikomatsakis Use diagnostic items instead of lang items for rfc2229 migrations This PR removes the `Send`, `UnwindSafe` and `RefUnwindSafe` lang items introduced in https://github.com/rust-lang/rust/pull/84730, and uses diagnostic items instead to check for `Send`, `UnwindSafe` and `RefUnwindSafe` traits for RFC2229 migrations. r? ```@nikomatsakis```
2021-07-08Move [debug_]assert_matches to mod {core, std}::assert.Mara Bos-2/+2