about summary refs log tree commit diff
path: root/library/std
AgeCommit message (Collapse)AuthorLines
2023-06-17Extend io::copy buffer reuse to BufReader tooThe 8472-74/+207
previously it was only able to use BufWriter. This was due to a limitation in the BufReader generics that prevented specialization. This change works around the issue by using `where Self: Read` instead of `where I: Read`. This limits our options, e.g. we can't access BufRead methods, but it happens to work out if we rely on some implementation details.
2023-06-16Rollup merge of #112226 - devnexen:netbsd_affinity, r=cuviperMichael Goulet-0/+23
std: available_parallelism using native netbsd api first before falling back to existing code paths like FreeBSD does.
2023-06-16Rollup merge of #111074 - WaffleLapkin:🌟unsizes_your_buf_reader🌟, ↵Michael Goulet-111/+118
r=Amanieu Relax implicit `T: Sized` bounds on `BufReader<T>`, `BufWriter<T>` and `LineWriter<T>` TL;DR: ```diff,rust -pub struct BufReader<R> { /* ... */ } +pub struct BufReader<R: ?Sized> { /* ... */ } -pub struct BufWriter<W: Write> { /* ... */ } +pub struct BufWriter<W: ?Sized + Write> { /* ... */ } -pub struct LineWriter<W: Write> { /* ... */ } +pub struct LineWriter<W: ?Sized + Write> { /* ... */ } ``` This allows using `&mut BufReader<dyn Read>`, for example. **This is an insta-stable change**.
2023-06-16Remove `#[cfg(all())]` workarounds from `c_char`Alex Macleod-5/+0
2023-06-16Rollup merge of #112579 - MikaelUrankar:freebsd_docs, r=cuviperDylan DPC-0/+1
Fix building libstd documentation on FreeBSD. It fixes the following error: ``` error[E0412]: cannot find type `sockcred2` in module `libc` --> library/std/src/os/unix/net/ancillary.rs:211:29 | 211 | pub struct SocketCred(libc::sockcred2); | ^^^^^^^^^ not found in `libc` ```
2023-06-16Rollup merge of #112535 - RalfJung:miri-test-libstd, r=cuviperDylan DPC-6/+7
reorder attributes to make miri-test-libstd work again Fixes fallout from https://github.com/rust-lang/rust/pull/110141
2023-06-15std: only depend on dlmalloc for wasm*-unknownJosh Stone-1/+1
It was already filtered out for emscripten, but wasi doesn't need dlmalloc either since it reuses `unix/alloc.rs`.
2023-06-15Extend `unused_must_use` to cover block exprs许杰友 Jieyou Xu (Joe)-1/+1
2023-06-15Auto merge of #104455 - the8472:dont-drain-on-drop, r=Amanieubors-74/+77
Don't drain-on-drop in DrainFilter impls of various collections. This removes drain-on-drop behavior from various unstable DrainFilter impls (not yet for HashSet/Map) because that behavior [is problematic](https://github.com/rust-lang/rust/issues/43244#issuecomment-641638196) (because it can lead to panic-in-drop when user closures panic) and may become forbidden if [this draft RFC passes](https://github.com/rust-lang/rfcs/pull/3288). closes #101122 [ACP](https://github.com/rust-lang/libs-team/issues/136) affected tracking issues * #43244 * #70530 * #59618 Related hashbrown update: https://github.com/rust-lang/hashbrown/pull/374
2023-06-14Fix `SocketAddrV6: Display` testsltdk-1/+1
2023-06-14Auto merge of #112624 - matthiaskrgr:rollup-db6ta1b, r=matthiaskrgrbors-15/+50
Rollup of 6 pull requests Successful merges: - #98202 (Implement `TryFrom<&OsStr>` for `&str`) - #107619 (Specify behavior of HashSet::insert) - #109814 (Stabilize String::leak) - #111974 (Update runtime guarantee for `select_nth_unstable`) - #112109 (Don't print unsupported split-debuginfo modes with `-Zunstable-options`) - #112506 (Properly check associated consts for infer placeholders) r? `@ghost` `@rustbot` modify labels: rollup
2023-06-14Rollup merge of #107619 - stepancheg:hash-set-insert, r=AmanieuMatthias Krüger-1/+23
Specify behavior of HashSet::insert `HashSet::insert` does not replace the value with equal value. Fixes #107581.
2023-06-14Rollup merge of #98202 - aticu:impl_tryfrom_osstr_for_str, r=AmanieuMatthias Krüger-14/+27
Implement `TryFrom<&OsStr>` for `&str` Recently when trying to work with `&OsStr` I was surprised to find this `impl` missing. Since the `to_str` method already existed the actual implementation is fairly non-controversial, except for maybe the choice of the error type. I chose an opaque error here instead of something like `std::str::Utf8Error`, since that would already make a number of assumption about the underlying implementation of `OsStr`. As this is a trait implementation, it is insta-stable, if I'm not mistaken? Either way this will need an FCP. I chose "1.64.0" as the version, since this is unlikely to land before the beta cut-off. `@rustbot` modify labels: +T-libs-api API Change Proposal: rust-lang/rust#99031 (accepted)
2023-06-14Auto merge of #112418 - ferrocene:pa-mir-opt-panic, r=ozkanonur,saethlinbors-0/+2
Add support for targets without unwinding in `mir-opt`, and improve `--bless` for it The main goal of this PR is to add support for targets without unwinding support in the `mir-opt` test suite, by adding the `EMIT_MIR_FOR_EACH_PANIC_STRATEGY` comment. Similarly to 32bit vs 64bit, when that comment is present, blessed output files will have the `.panic-unwind` or `.panic-abort` suffix, and the right one will be chosen depending on the target's panic strategy. The `EMIT_MIR_FOR_EACH_PANIC_STRATEGY` comment replaced all the `ignore-wasm32` comments in the `mir-opt` test suite, as those comments were added due to `wasm32` being a target without unwinding support. The comment was also added on other tests that were only executed on x86 but were still panic strategy dependent. The `mir-opt` suite was then blessed, which caused a ton of churn as most of the existing output files had to be renamed and (mostly) duplicated with the abort strategy. --- After [asking on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/mir-opt.20tests.20and.20panic.3Dabort), the main concern about this change is it'd make blessing the `mir-opt` suite even harder, as you'd need to both bless it with an unwinding target and an aborting target. This exacerbated the current situation, where you'd need to bless it with a 32bit and a 64bit target already. Because of that, this PR also makes significant enhancements to `--bless` for the `mir-opt` suite, where it will automatically bless the suite four times with different targets, while requiring minimal cross-compilation. To handle the 32bit vs 64bit blessing, there is now an hardcoded list of target mapping between 32bit and 64bit. The goal of the list is to find a related target that will *probably* work without requiring additional cross-compilation toolchains on the system. If a mapping is found, bootstrap will bless the suite with both targets, otherwise just with the current target. To handle the panic strategy blessing (abort vs unwind), I had to resort to what I call "synthetic targets". For each of the target we're blessing (so either the current one, or a 32bit and a 64bit depending on the previous paragraph), bootstrap will extract the JSON spec of the target and change it to include `"panic-strategy": "abort"`. It will then build the standard library with this synthetic target, and bless the `mir-opt` suite with it. As a result of these changes, blessing the `mir-opt` suite will actually bless it two or four times with different targets, ensuring all possible variants are actually blessed. --- This PR is best reviewed commit-by-commit. r? `@jyn514` cc `@saethlin` `@oli-obk`
2023-06-14update hashbrown and replace Hash{Set,Map}::DrainFilter with ExtractIfThe 8472-74/+77
2023-06-13fix: get the l4re target working againHenrik Böving-3/+23
2023-06-13Fix building the documentation on FreeBSD.MikaelUrankar-0/+1
It fixes the following error: error[E0412]: cannot find type `sockcred2` in module `libc` --> library/std/src/os/unix/net/ancillary.rs:211:29 | 211 | pub struct SocketCred(libc::sockcred2); | ^^^^^^^^^ not found in `libc`
2023-06-13Rollup merge of #112558 - eltociear:patch-21, r=thomccMatthias Krüger-1/+1
Fix typo in mod.rs assoicated -> associated
2023-06-13Fix typo in mod.rsIkko Eltociear Ashimine-1/+1
assoicated -> associated
2023-06-12Add comment for arm_shim in generate-windows-sysbdbai-0/+3
2023-06-12Add windows_sys typedef for Win ARM32bdbai-0/+17
2023-06-12Implement `TryFrom<&OsStr>` for `&str`aticu-14/+27
2023-06-12make sure the standard library compiles properly with synthetic targetsPietro Albini-0/+2
It might happen that a synthetic target name does not match one of the hardcoded ones in std's build script, causing std to fail to build. This commit changes the std build script avoid including the restricted-std feature unconditionally when a synthetic target is being built.
2023-06-11reorder attributes to make miri-test-libstd work againRalf Jung-6/+7
2023-06-11Rollup merge of #112497 - icecream17:patch-1, r=Mark-SimulacrumMatthias Krüger-2/+2
abs_sub: fix typo 0[-:][+.]0
2023-06-10implement `Sync` for `mpsc::Sender`Ibraheem Ahmed-2/+2
2023-06-10abs_sub: fix typo 0[-:][+.]0icecream17-2/+2
2023-06-10Keep uwp specific code in sync with windows-sysbdbai-5/+4
2023-06-10Lazy load ntdll functions on UWPbdbai-2/+61
2023-06-08Auto merge of #112292 - thomcc:tls-ohno, r=m-ou-sebors-12/+33
Avoid unwind across `extern "C"` in `thread_local::fast_local` This is a minimal fix for #112285, in case we want a simple patch that can be easily to backported if that's desirable. *(Note: I have another broader cleanup which I've mostly omitted from here to avoid clutter, except for the `Cell` change, which isn't needed to fix UB, but simplifies safety comments).* The only tier-1 target that this occurs on in a way that seems likely to cause problems in practice linux-gnu, although I believe some folks care about that platform somewhat 😉. I'm unsure how big of an issue this is. I've seen stuff like this behave quite badly, but there's a number of reasons to think this might actually be "fine in practice". I've hedged my bets and assumed we'll backport this at least to beta but my feeling is that there's not enough evidence this is a problem worth backporting further than that. ### More details This issue seems to have existed since `thread_local!`'s `const` init functionality was added. It occurs if you have a `const`-initialized thread local for a type that `needs_drop`, the drop panics, and you're on a target with support for static thread locals. In this case, we will end up defining an `extern "C"` function in the user crate rather than in libstd, and because the user crate will not have `#![feature(c_unwind)]` enabled, their panic will not be caught by an auto-inserted abort guard. In practice, the actual situation where problems are likely[^ub] is somewhat narrower. On most targets with static thread locals, we manage the TLS dtor list by hand (for reentrancy reasons among others). In these cases, while the users code may panic, we're calling it inside our own `extern "C"` (or `extern "system"`) function, which seems to (at least in practice) catch the panic and convert it to an abort. However, on a few targets, most notably linux-gnu with recent glibc (but also fuchsia and redox), a tls dtor registration mechanism exists which we can actually use directly, [`__cxa_thread_atexit_impl`](https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/thread_local_dtor.rs#L26-L36). This is the case that seems most likely to be a cause for concern, as now we're passing a function to the system library and panicking out of it in a case where there are may not be Rust frames above it on the call stack (since it's running thread shutdown), and even if there were, it may not be prepared to handle such unwinding. If that's the case, it'd be bad. Is it? Dunno. The fact that it's a `__cxa_*` function makes me think they probably have considered that the callback could throw but I have no evidence here and it doesn't seem to be written down anywhere, so it's just a guess. (I would not be surprised if someone comes into this thread to tell me how definitely-bad-news it is). That said, as I said, all this is actually UB! If this isn't a "technically UB but fine in practice", but all bets are off if this is the kind of thing we are telling LLVM about. [^ub]: This is UB so take that with a grain of salt -- I'm absolutely making assumptions about how the UB will behave "in practice" here, which is almost certainly a mistake.
2023-06-07Make Unix or Windows mandatory for the `switch-stdout.rs` testMoskalykA-0/+2
2023-06-07Move two tests from `tests/ui/std` to `library/std/tests`MoskalykA-0/+87
2023-06-06Fix documentation build on FreeBSDDan McGregor-1/+7
After the socket ancillary data implementation was introduced, the build was broken on FreeBSD, add the same workaround as for the existing implementations.
2023-06-06Bumped libc versionNikolay Arhipov-1/+1
2023-06-06std: available_parallelism using native netbsd api firstDavid Carlier-0/+23
before falling back to existing code paths like FreeBSD does.
2023-06-05Simplified bool to int conversionNikolay Arhipov-4/+1
2023-06-05Std support improvement for ps vita targetNikolay Arhipov-19/+59
2023-06-04Avoid unwind across `extern "C"` in `thread_local::fast_local.rs`Thom Chiovoloni-12/+33
2023-06-04Rollup merge of #112172 - tshepang:patch-1, r=Mark-SimulacrumMatthias Krüger-1/+1
doc: improve explanation
2023-06-03Auto merge of #109432 - flba-eb:108594_forkspawn_exponential_backoff, ↵bors-14/+62
r=workingjubilee QNX Neutrino: exponential backoff when fork/spawn needs a retry Fixes #108594: When retrying, sleep with an exponential duration. When sleep duration is lower than minimum possible sleeping time, yield instead (this will not be often due to the exponential increase of duration). Minimum possible sleeping time is determined using `libc::clock_getres` but only when spawn/fork failed the first time in a request. This is cached using a LazyLock. CC `@gh-tr` r? `@workingjubilee` `@rustbot` label +O-neutrino
2023-06-02Rollup merge of #111647 - klensy:cstr, r=oli-obkMatthias Krüger-26/+26
use c literals in compiler and library Use c literals #108801 in compiler and library currently blocked on: * <strike>rustfmt: don't know how to format c literals</strike> nope, nightly one works. * <strike>bootstrap</strike> r? `@ghost` `@rustbot` blocked
2023-06-02Only determine clock res once; give up before sleeping more than 1 secondFlorian Bartels-23/+37
2023-06-02Retry to fork/spawn with exponential backoffFlorian Bartels-10/+44
2023-06-02fix ptr castklensy-7/+9
2023-06-01doc: improve explanationTshepang Mbambo-1/+1
2023-05-31Fix bug in utf16_to_utf8 for zero length stringsShane Murphy-0/+13
This fixes the behavior of sending EOF by pressing Ctrl+Z => Enter in a windows console. Previously, that would trip the unpaired surrogate error, whereas now we correctly detect EOF.
2023-05-31use c literals in libraryklensy-25/+23
2023-05-31Auto merge of #111076 - ↵bors-14/+16
notriddle:notriddle/silence-private-dep-trait-impl-suggestions, r=cjgillot diagnostics: exclude indirect private deps from trait impl suggest Fixes #88696
2023-05-31Rollup merge of #112103 - Mark-Simulacrum:bootstrap-update, r=clubby789Matthias Krüger-6/+6
Bootstrap update to 1.71 beta Best reviewed by-commit.
2023-05-30add doc on From<OwnedFd/Handle> impl for ChildStd*Vincent Thiberville-0/+24