about summary refs log tree commit diff
path: root/library/std
AgeCommit message (Collapse)AuthorLines
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-21Update hashbrown to 0.12.0Amanieu d'Antras-1/+1
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
2022-01-13Remove `&mut` from `io::read_to_string` signatureNoah Lev-2/+2
`@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. [1]: https://github.com/rust-lang/rust/issues/80218#issuecomment-874322129
2022-01-13Rollup merge of #91938 - yaahc:error-reporter, r=m-ou-seMatthias Krüger-4/+1048
Add `std::error::Report` type This is a continuation of https://github.com/rust-lang/rust/pull/90174, split into a separate PR since I cannot push to ```````@seanchen1991``````` 's fork
2022-01-13Auto merge of #92553 - m-ou-se:thread-join-simplify, r=Mark-Simulacrumbors-9/+9
Simpilfy thread::JoinInner. `JoinInner`'s `native` field was an `Option`, but that's unnecessary. Also, thanks to `Arc::get_mut`, there's no unsafety needed in `JoinInner::join()`.
2022-01-12Use the correct `cvt` for converting socket errors on Windows.Dan Gohman-1/+2
`WSADuplicateSocketW` returns 0 on success, which differs from handle-oriented functions which return 0 on error. Use `sys::net::cvt` to handle its return value, which handles the socket convention of returning 0 on success, rather than `sys::cvt`, which handles the handle-oriented convention of returning 0 on failure.
2022-01-12Remove deprecated LLVM-style inline assemblyTomasz Miąsko-6/+4
2022-01-12Rollup merge of #92748 - david-perez:eliminate-boxed-wording-std-error, ↵Matthias Krüger-6/+6
r=Mark-Simulacrum Eliminate "boxed" wording in `std::error::Error` documentation In commit 29403ee, documentation for the methods on `std::any::Any` was modified so that they referred to the concrete value behind the trait object as the "inner" value. This is a more accurate wording than "boxed": while putting trait objects inside boxes is arguably the most common use, they can also be placed behind other pointer types like `&mut` or `std::sync::Arc`. This commit does the same documentation changes for `std::error::Error`.
2022-01-12Rollup merge of #92720 - rosik:patch-1, r=m-ou-seMatthias Krüger-1/+1
Fix doc formatting for time.rs The doc states that instants are not steady, but the word "not" wasn't highlighted in bold.
2022-01-12Rollup merge of #92709 - joshtriplett:file-options-docs, r=Mark-SimulacrumMatthias Krüger-4/+5
Improve documentation for File::options to give a more likely example `File::options().read(true).open(...)` is equivalent to just `File::open`. Change the example to set the `append` flag instead, and then change the filename to something more likely to be written in append mode.
2022-01-11Inline std::os::unix::ffi::OsStringExt methodsKonrad Borowski-0/+2