about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2021-07-26Auto merge of #87430 - devnexen:netbsd_ucred_enabled, r=joshtriplettbors-2/+16
netbsd enabled ucred
2021-07-25ignore comments in tidy-filelengthibraheemdev-2/+0
2021-07-25macos current_exe using directly libc instead.David CARLIER-5/+2
2021-07-24Auto merge of #84111 - bstrie:hashfrom, r=joshtriplettbors-21/+108
Stabilize `impl From<[(K, V); N]> for HashMap` (and friends) In addition to allowing HashMap to participate in Into/From conversion, this adds the long-requested ability to use constructor-like syntax for initializing a HashMap: ```rust let map = HashMap::from([ (1, 2), (3, 4), (5, 6) ]); ``` This addition is highly motivated by existing precedence, e.g. it is already possible to similarly construct a Vec from a fixed-size array: ```rust let vec = Vec::from([1, 2, 3]); ``` ...and it is already possible to collect a Vec of tuples into a HashMap (and vice-versa): ```rust let vec = Vec::from([(1, 2)]); let map: HashMap<_, _> = vec.into_iter().collect(); let vec: Vec<(_, _)> = map.into_iter().collect(); ``` ...and of course it is likewise possible to collect a fixed-size array of tuples into a HashMap ([but not vice-versa just yet](https://github.com/rust-lang/rust/issues/81615)): ```rust let arr = [(1, 2)]; let map: HashMap<_, _> = std::array::IntoIter::new(arr).collect(); ``` Therefore this addition seems like a no-brainer. As for any impl, this would be insta-stable.
2021-07-24Hide allocator details from TryReserveErrorKornel-5/+15
2021-07-24Remove unnecessary condition in Barrier::wait()twetzel59-1/+1
2021-07-24Update std_collections_from_array stability versionbstrie-2/+2
2021-07-24Rollup merge of #87395 - ericonr:patch-1, r=joshtriplettManish Goregaokar-4/+3
Clear up std::env::set_var panic section. The "K" parameter was being referred to as "key", which wasn't introduced anywhere.
2021-07-24netbsd enabled ucredDavid Carlier-2/+16
2021-07-24Auto merge of #84589 - In-line:zircon-thread-name, r=JohnTitorbors-4/+30
Implement setting thread name for Fuchsia
2021-07-23Fix parameter names in std::env documentation.Érico Nogueira Rolim-4/+3
The function parameters were renamed, but the documentation wasn't.
2021-07-24Rollup merge of #87175 - inquisitivecrystal:inner-error, r=kennytmYuki Okushi-4/+2
Stabilize `into_parts()` and `into_error()` This stabilizes `IntoInnerError`'s `into_parts()` and `into_error()` methods, currently gated behind the `io_into_inner_error_parts` feature. The FCP has [already completed.](https://github.com/rust-lang/rust/issues/79704#issuecomment-880652967) Closes #79704.
2021-07-24Rollup merge of #87171 - Alexendoo:bufwriter-option, r=Mark-SimulacrumYuki Okushi-10/+14
Remove Option from BufWriter Fixes #72925
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`