about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-01-24Rollup merge of #93152 - ivmarkov:master, r=m-ou-seMatthias Krüger-3/+7
Fix STD compilation for the ESP-IDF target (regression from CVE-2022-21658) Commit https://github.com/rust-lang/rust/commit/54e22eb7dbb615bd44355028d3fd867aa93c0972 broke the compilation of STD for the ESP-IDF embedded "unix-like" Tier 3 target, because the fix for [CVE-2022-21658](https://blog.rust-lang.org/2022/01/20/Rust-1.58.1.html) uses [libc flags](https://github.com/esp-rs/esp-idf-svc/runs/4892221554?check_suite_focus=true) which are not supported on the ESP-IDF platform. This PR simply redirects the ESP-IDF compilation to the "classic" implementation, similar to REDOX. This should be safe because: * Neither of the two filesystems supported by ESP-IDF (spiffs and fatfs) support [symlinks](https://github.com/natevw/fatfs/blob/master/README.md) in the first place * There is no notion of fs permissions at all, as the ESP-IDF is an embedded platform that does not have the notion of users, groups, etc. * Similarly, ESP-IDF has just one "process" - the firmware itself - which contains the user code and the "OS" fused together and running with all permissions
2022-01-24Rollup merge of #92513 - Xuanwo:path-buf, r=dtolnayMatthias Krüger-0/+19
std: Implement try_reserve and try_reserve_exact on PathBuf Part of https://github.com/rust-lang/rust/issues/91789 Signed-off-by: Xuanwo <github@xuanwo.io>
2022-01-24Use `NtCreateFile` instead of `NtOpenFile` to open a fileChris Denton-7/+18
2022-01-23Rollup merge of #92555 - m-ou-se:scoped-threads, r=AmanieuMatthias Krüger-27/+382
Implement RFC 3151: Scoped threads. This implements https://github.com/rust-lang/rfcs/pull/3151 r? `@Amanieu`
2022-01-23Add os::unix::net::SocketAddr::unixThomas de Zeeuw-1/+68
Creates a new SocketAddr from a path, supports both regular paths and abstract namespaces.
2022-01-22Auto merge of #92998 - Amanieu:hashbrown12, r=Mark-Simulacrumbors-5/+16
Update hashbrown to 0.12.0 [Changelog](https://github.com/rust-lang/hashbrown/blob/master/CHANGELOG.md#v0120---2022-01-17)
2022-01-22Add test for thread::Scope invariance.Mara Bos-0/+13
2022-01-22Add tracking issue number for scoped_threads.Mara Bos-2/+2
2022-01-22Simplify Send/Sync of std::thread::Packet.Mara Bos-7/+5
2022-01-22Rollup merge of #92828 - Amanieu:unwind-abort, r=dtolnayMatthias Krüger-9/+21
Print a helpful message if unwinding aborts when it reaches a nounwind function This is implemented by routing `TerminatorKind::Abort` back through the panic handler, but with a special flag in the `PanicInfo` which indicates that the panic handler should *not* attempt to unwind the stack and should instead abort immediately. This is useful for the planned change in https://github.com/rust-lang/lang-team/issues/97 which would make `Drop` impls `nounwind` by default. ### Code ```rust #![feature(c_unwind)] fn panic() { panic!() } extern "C" fn nounwind() { panic(); } fn main() { nounwind(); } ``` ### Before ``` $ ./test thread 'main' panicked at 'explicit panic', test.rs:4:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Illegal instruction (core dumped) ``` ### After ``` $ ./test thread 'main' panicked at 'explicit panic', test.rs:4:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread 'main' panicked at 'panic in a function that cannot unwind', test.rs:7:1 stack backtrace: 0: 0x556f8f86ec9b - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdccefe11a6ac4396 1: 0x556f8f88ac6c - core::fmt::write::he152b28c41466ebb 2: 0x556f8f85d6e2 - std::io::Write::write_fmt::h0c261480ab86f3d3 3: 0x556f8f8654fa - std::panicking::default_hook::{{closure}}::h5d7346f3ff7f6c1b 4: 0x556f8f86512b - std::panicking::default_hook::hd85803a1376cac7f 5: 0x556f8f865a91 - std::panicking::rust_panic_with_hook::h4dc1c5a3036257ac 6: 0x556f8f86f079 - std::panicking::begin_panic_handler::{{closure}}::hdda1d83c7a9d34d2 7: 0x556f8f86edc4 - std::sys_common::backtrace::__rust_end_short_backtrace::h5b70ed0cce71e95f 8: 0x556f8f865592 - rust_begin_unwind 9: 0x556f8f85a764 - core::panicking::panic_no_unwind::h2606ab3d78c87899 10: 0x556f8f85b910 - test::nounwind::hade6c7ee65050347 11: 0x556f8f85b936 - test::main::hdc6e02cb36343525 12: 0x556f8f85b7e3 - core::ops::function::FnOnce::call_once::h4d02663acfc7597f 13: 0x556f8f85b739 - std::sys_common::backtrace::__rust_begin_short_backtrace::h071d40135adb0101 14: 0x556f8f85c149 - std::rt::lang_start::{{closure}}::h70dbfbf38b685e93 15: 0x556f8f85c791 - std::rt::lang_start_internal::h798f1c0268d525aa 16: 0x556f8f85c131 - std::rt::lang_start::h476a7ee0a0bb663f 17: 0x556f8f85b963 - main 18: 0x7f64c0822b25 - __libc_start_main 19: 0x556f8f85ae8e - _start 20: 0x0 - <unknown> thread panicked while panicking. aborting. Aborted (core dumped) ```
2022-01-22Disable test_try_reserve on AndroidAmanieu d'Antras-0/+1
2022-01-21Rollup merge of #93134 - tlyu:delete-stdin-split, r=AmanieuMatthias Krüger-24/+1
delete `Stdin::split` forwarder Part of #87096. Delete the `Stdin::split` forwarder because it's seen as too niche to expose at this level. `@rustbot` label T-libs-api A-io
2022-01-21Rollup merge of #93109 - JakobDegen:arc-docs, r=m-ou-seMatthias Krüger-7/+13
Improve `Arc` and `Rc` documentation This makes two changes (I can split the PR if necessary, but the changes are pretty small): 1. A bunch of trait implementations claimed to be zero cost; however, they use the `Arc<T>: From<Box<T>>` impl which is definitely not free, especially for large dynamically sized `T`. 2. The code in deferred initialization examples unnecessarily used excessive amounts of `unsafe`. This has been reduced.
2022-01-21Rollup merge of #92586 - esp-rs:bugfix/allocation-alignment-espidf, r=yaahcMatthias Krüger-2/+8
Set the allocation MIN_ALIGN for espidf to 4. Closes https://github.com/esp-rs/rust/issues/99. cc: `@ivmarkov`
2022-01-21Update HashMap::try_reserve test to version from hashbrownAmanieu d'Antras-5/+15
2022-01-21Old versions of Android generate SIGSEGV from libc::abortAmanieu d'Antras-1/+6
2022-01-21fs: Use readdir() instead of readdir_r() on AndroidTavian Barnes-0/+10
Bionic also guarantees that readdir() is thread-safe enough.
2022-01-21fs: Use readdir() instead of readdir_r() on LinuxTavian Barnes-13/+30
readdir() is preferred over readdir_r() on Linux and many other platforms because it more gracefully supports long file names. Both glibc and musl (and presumably all other Linux libc implementations) guarantee that readdir() is thread-safe as long as a single DIR* is not accessed concurrently, which is enough to make a readdir()-based implementation of ReadDir safe. This implementation is already used for some other OSes including Fuchsia, Redox, and Solaris. See #40021 for more details. Fixes #86649. Fixes #34668.
2022-01-21fs: Implement more ReadDir methods in terms of name_cstr()Tavian Barnes-23/+18
2022-01-21Fix STD compilation for the ESP-IDF targetivmarkov-3/+7
2022-01-20delete `Stdin::split` forwarderTaylor Yu-24/+1
2022-01-20Rollup merge of #93112 - pietroalbini:pa-cve-2022-21658-nightly, r=pietroalbiniMatthias Krüger-52/+838
Fix CVE-2022-21658 See https://blog.rust-lang.org/2022/01/20/cve-2022-21658.html. Patches reviewed by `@m-ou-se.` r? `@ghost`
2022-01-20Rollup merge of #92992 - kornelski:backtraceopt, r=Mark-SimulacrumMatthias Krüger-8/+19
Help optimize out backtraces when disabled The comment in `rust_backtrace_env` says: > // If the `backtrace` feature of this crate isn't enabled quickly return > // `None` so this can be constant propagated all over the place to turn > // optimize away callers. but this optimization has regressed, because the only caller of this function had an alternative path that unconditionally (and pointlessly) asked for a full backtrace, so the disabled state couldn't propagate. I've added a getter for the full format that respects the feature flag, so that the caller will now be able to really optimize out the disabled backtrace path. I've also made `rust_backtrace_env` trivially inlineable when backtraces are disabled.
2022-01-20Fix compilation for a few tier 2 targetsHans Kratz-8/+5
2022-01-20Correct docs in `Arc` and `Rc`.Jakob Degen-7/+13
A number of trait implementations incorrectly claimed to be zero cost.
2022-01-19Write for Cursor with a custom AllocatorJosh Stone-7/+23
2022-01-19impl Write for Cursor<[u8; N]>Josh Stone-0/+35
2022-01-19Refactor tests of Write for Cursor<_>Josh Stone-44/+28
2022-01-19`impl Display for io::ErrorKind`Joshua Nelson-1/+17
This avoids having to convert from `ErrorKind` to `Error` just to print the error message.
2022-01-19Update std::fs::remove_dir_all documentationPietro Albini-4/+8
2022-01-19Fix CVE-2022-21658 for WASIAlex Crichton-8/+63
2022-01-19Fix CVE-2022-21658 for UNIX-likeHans Kratz-13/+351
2022-01-19Fix CVE-2022-21658 for WindowsChris Denton-27/+419
2022-01-19Rollup merge of #92124 - ↵Matthias Krüger-22/+45
AngelicosPhosphoros:remove_extra_alloc_in_cstring_new_35838, r=Mark-Simulacrum Little improves in CString `new` when creating from slice Old code already contain optimization for cases with `&str` and `&[u8]` args. This commit adds a specialization for `&mut[u8]` too. Also, I added usage of old slice in search for zero bytes instead of new buffer because it produce better code for constant inputs on Windows LTO builds. For other platforms, this wouldn't cause any difference because it calls `libc` anyway. Inlined `_new` method into spec trait to reduce amount of code generated to `CString::new` callers.
2022-01-18Rollup merge of #93016 - Amanieu:vec_spare_capacity, r=Mark-SimulacrumMatthias Krüger-1/+0
Stabilize vec_spare_capacity Closes #75017
2022-01-18Rollup merge of #92866 - maxwase:does_exist_typo, r=Mark-SimulacrumMatthias Krüger-2/+2
"Does exists" typos fix Fixed some typos
2022-01-17Stabilize vec_spare_capacityAmanieu d'Antras-1/+0
Closes #75017
2022-01-17Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieubors-6/+4
Remove deprecated LLVM-style inline assembly The `llvm_asm!` was deprecated back in #87590 1.56.0, with intention to remove it once `asm!` was stabilized, which already happened in #91728 1.59.0. Now it is time to remove `llvm_asm!` to avoid continued maintenance cost. Closes #70173. Closes #92794. Closes #87612. Closes #82065. cc `@rust-lang/wg-inline-asm` r? `@Amanieu`
2022-01-17Help optimize out backtraces when disabledKornel-8/+19
2022-01-17Add PanicInfo::can_unwind which indicates whether a panic handler isAmanieu d'Antras-8/+15
allowed to trigger unwinding.
2022-01-16Rollup merge of #92619 - Alexendoo:macro-diagnostic-items, r=matthewjasperMatthias Krüger-0/+6
Add diagnostic items for macros For use in Clippy, it adds diagnostic items to all the stable public macros Clippy has lints that look for almost all of these (currently by name or path), but there are a few that aren't currently part of any lint, I could remove those if it's preferred to add them as needed rather than ahead of time
2022-01-16Auto merge of #92598 - Badel2:panic-update-hook, r=yaahcbors-0/+82
Implement `panic::update_hook` Add a new function `panic::update_hook` to allow creating panic hooks that forward the call to the previously set panic hook, without race conditions. It works by taking a closure that transforms the old panic hook into a new one, while ensuring that during the execution of the closure no other thread can modify the panic hook. This is a small function so I hope it can be discussed here without a formal RFC, however if you prefer I can write one. Consider the following example: ```rust let prev = panic::take_hook(); panic::set_hook(Box::new(move |info| { println!("panic handler A"); prev(info); })); ``` This is a common pattern in libraries that need to do something in case of panic: log panic to a file, record code coverage, send panic message to a monitoring service, print custom message with link to github to open a new issue, etc. However it is impossible to avoid race conditions with the current API, because two threads can execute in this order: * Thread A calls `panic::take_hook()` * Thread B calls `panic::take_hook()` * Thread A calls `panic::set_hook()` * Thread B calls `panic::set_hook()` And the result is that the original panic hook has been lost, as well as the panic hook set by thread A. The resulting panic hook will be the one set by thread B, which forwards to the default panic hook. This is not considered a big issue because the panic handler setup is usually run during initialization code, probably before spawning any other threads. Using the new `panic::update_hook` function, this race condition is impossible, and the result will be either `A, B, original` or `B, A, original`. ```rust panic::update_hook(|prev| { Box::new(move |info| { println!("panic handler A"); prev(info); }) }); ``` I found one real world use case here: https://github.com/dtolnay/proc-macro2/blob/988cf403e741aadfd5340bbf67e35e1062a526aa/src/detection.rs#L32 the workaround is to detect the race condition and panic in that case. The pattern of `take_hook` + `set_hook` is very common, you can see some examples in this pull request, so I think it's natural to have a function that combines them both. Also using `update_hook` instead of `take_hook` + `set_hook` reduces the number of calls to `HOOK_LOCK.write()` from 2 to 1, but I don't expect this to make any difference in performance. ### Unresolved questions: * `panic::update_hook` takes a closure, if that closure panics the error message is "panicked while processing panic" which is not nice. This is a consequence of holding the `HOOK_LOCK` while executing the closure. Could be avoided using `catch_unwind`? * Reimplement `panic::set_hook` as `panic::update_hook(|_prev| hook)`?
2022-01-15stabilize windows_process_extensions_raw_argJacob Kiesel-1/+1
2022-01-15Rollup merge of #92863 - camelid:read_to_string-rm-mut, r=m-ou-seMatthias Krüger-2/+2
Remove `&mut` from `io::read_to_string` signature ``@m-ou-se`` [realized][1] that because `Read` is implemented for `&mut impl Read`, there's no need to take `&mut` in `io::read_to_string`. Removing the `&mut` from the signature allows users to remove the `&mut` from their calls (and thus pass an owned reader) if they don't use the reader later. r? `@m-ou-se` [1]: https://github.com/rust-lang/rust/issues/80218#issuecomment-874322129
2022-01-15Rollup merge of #92775 - xfix:osstringext-inline, r=m-ou-seMatthias Krüger-0/+2
Inline std::os::unix::ffi::OsStringExt methods Those methods essentially do nothing at assembly level. On Unix systems, `OsString` is represented as a `Vec` without performing any transformations.
2022-01-15Rollup merge of #92684 - ibraheemdev:patch-10, r=m-ou-seMatthias Krüger-0/+2
Export `tcp::IntoIncoming` Added in #88339 but not publicly exported.
2022-01-14Rollup merge of #92768 - ojeda:stabilize-maybe_uninit_extra, r=Mark-SimulacrumMatthias Krüger-1/+0
Partially stabilize `maybe_uninit_extra` This covers: ```rust impl<T> MaybeUninit<T> { pub unsafe fn assume_init_read(&self) -> T { ... } pub unsafe fn assume_init_drop(&mut self) { ... } } ``` It does not cover the const-ness of `write` under `const_maybe_uninit_write` nor the const-ness of `assume_init_read` (this commit adds `const_maybe_uninit_assume_init_read` for that). FCP: https://github.com/rust-lang/rust/issues/63567#issuecomment-958590287. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-01-14Typos fixMaxwase-2/+2
2022-01-13Set the allocation MIN_ALIGN for espidf to 4.Scott Mabin-2/+8
2022-01-13fix stability attribute for `tcp::IntoIncoming`Ibraheem Ahmed-1/+3