about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2021-07-29Fix may not to appropriate might not or must notAli Malik-39/+39
2021-07-29Rollup merge of #86839 - D1mon:patch-1, r=JohnTitorYuki Okushi-0/+2
Add doc aliases to fs.rs Add aliases for create_dir, create_dir_all, remove_dir, remove_dir_all
2021-07-29Rollup merge of #81050 - yoshuawuyts:stabilize-task-ready, r=m-ou-seYuki Okushi-1/+0
Stabilize core::task::ready! _Tracking issue: https://github.com/rust-lang/rust/issues/70922_ This PR stabilizes the `task::ready!` macro. Similar to https://github.com/rust-lang/rust/pull/80886, this PR was waiting on https://github.com/rust-lang/rust/issues/74355 to be fixed. The `task::ready!` API has existed in the futures ecosystem for several years, and was added on nightly last year in https://github.com/rust-lang/rust/pull/70817. The motivation for this macro is the same as it was back then: virtually every single manual future implementation makes use of this; so much so that it's one of the few things included in the [futures-core](https://docs.rs/futures-core/0.3.12/futures_core) library. r? ``@tmandry`` cc/ ``@rust-lang/wg-async-foundations`` ``@rust-lang/libs`` ## Example ```rust use core::task::{Context, Poll}; use core::future::Future; use core::pin::Pin; async fn get_num() -> usize { 42 } pub fn do_poll(cx: &mut Context<'_>) -> Poll<()> { let mut f = get_num(); let f = unsafe { Pin::new_unchecked(&mut f) }; let num = ready!(f.poll(cx)); // ... use num Poll::Ready(()) } ```
2021-07-29Add some doc aliasesD1mon-0/+2
Add `mkdir` to `create_dir`, `rmdir` to `remove_dir`.
2021-07-28thread set_name haiku implementation.David Carlier-2/+9
2021-07-28Add new const_format_args!() macro and use it in panics.Mara Bos-5/+6
2021-07-28Make const panic!("..") work in Rust 2021.Mara Bos-0/+1
During const eval, this replaces calls to core::panicking::panic_fmt and std::panicking::being_panic_fmt with a call to a new const fn: core::panicking::const_panic_fmt. That function uses fmt::Arguments::as_str() to get the str and calls panic_str with that instead. panic!() invocations with formatting arguments are still not accepted, as the creation of such a fmt::Arguments cannot be done in constant functions right now.
2021-07-28stack overflow handler specific openbsd fix.David Carlier-8/+9
On this platform, when doing stack allocation, MAP_STACK is needed otherwise the mapping fails.
2021-07-28Rollup merge of #87507 - jethrogb:jb/sgx-unmoveable-mutex, r=dtolnayYuki Okushi-1/+3
SGX mutex is *not* moveable Reverts the erroneous change in #85029.
2021-07-28Rollup merge of #87330 - inquisitivecrystal:extend-reserve, r=JohnTitorYuki Okushi-9/+1
Use hashbrown's `extend_reserve()` in `HashMap` When we added `extend_reserve()` to our implementation of `Extend` for `HashMap`, hashbrown didn't have a version we could use. Now that hashbrown has added it, we should use its version instead of implementing it ourself.
2021-07-27Update testsJacob Pratt-1/+1
2021-07-27Stabilize `const_fn_transmute`Jacob Pratt-2/+2
2021-07-27Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by defaultAaron Hill-1/+1
2021-07-27Rollup merge of #87446 - devnexen:macos_update, r=dtolnayYuki Okushi-5/+2
macos current_exe using directly libc instead.
2021-07-27Rollup merge of #87354 - Wind-River:2021_master, r=kennytmYuki Okushi-1/+3
Update VxWork's UNIX support 1. VxWorks does not provide glibc 2. VxWorks does provide `sigemptyset` and `sigaddset` Note: these changes are concurrent to [this PR](https://github.com/rust-lang/libc/pull/2295) in libc.
2021-07-27Add warning to SGX mutex implementationJethro Beekman-0/+2
2021-07-27Revert "SGX mutex is movable"Jethro Beekman-1/+1
This reverts commit 30b82e0f96579d9f897c4e2a780af82662d89772.
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.