about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2023-01-12Rollup merge of #106638 - RalfJung:realstd, r=thomccMatthias Krüger-7/+15
std tests: use __OsLocalKeyInner from realstd This is basically the same as https://github.com/rust-lang/rust/pull/100201, but for __OsLocalKeyInner: Some std tests are failing in Miri on Windows because [this static](https://github.com/rust-lang/rust/blob/a377893da2cd7124e5a18c7116cbb70e16dd5541/library/std/src/sys/windows/thread_local_key.rs#L234-L239) is getting duplicated, and Miri does not handle that properly -- Miri does not support this magic `.CRT$XLB` linker section, but instead just looks up this particular hard-coded static in the standard library. This PR lets the test suite use the std static instead of having its own copy. Fixes https://github.com/rust-lang/miri/issues/2754 r? `@thomcc`
2023-01-11Rollup merge of #106664 - chenyukang:yukang/fix-106597-remove-lseek, r=cuvipernils-4/+6
Remove unnecessary lseek syscall when using std::fs::read Fixes #106597 r? ```@bjorn3```
2023-01-11Change `src/test` to `tests` in source files, fix tidy and testsAlbert Larsan-1/+1
2023-01-11use with_capacity in read read_to_stringyukang-4/+2
2023-01-09std tests: use __OsLocalKeyInner from realstdRalf Jung-7/+15
2023-01-09std test: better type name, clarifying commentRalf Jung-12/+12
2023-01-08Rollup merge of #103104 - SUPERCILEX:sep-ref, r=dtolnayYuki Okushi-1/+1
Stabilize `main_separator_str` See reasoning here: https://github.com/rust-lang/rust/issues/94071#issuecomment-1279872605. Closes #94071.
2023-01-08Auto merge of #104658 - thomcc:rand-update-and-usable-no_std, r=Mark-Simulacrumbors-10/+39
Update `rand` in the stdlib tests, and remove the `getrandom` feature from it. The main goal is actually removing `getrandom`, so that eventually we can allow running the stdlib test suite on tier3 targets which don't have `getrandom` support. Currently those targets can only run the subset of stdlib tests that exist in uitests, and (generally speaking), we prefer not to test libstd functionality in uitests, which came up recently in https://github.com/rust-lang/rust/pull/104095 and https://github.com/rust-lang/rust/pull/104185. Additionally, the fact that we can't update `rand`/`getrandom` means we're stuck with the old set of tier3 targets, so can't test new ones. ~~Anyway, I haven't checked that this actually does allow use on tier3 targets (I think it does not, as some work is needed in stdlib submodules) but it moves us slightly closer to this, and seems to allow at least finally updating our `rand` dep, which definitely improves the status quo.~~ Checked and works now. For the most part, our tests and benchmarks are fine using hard-coded seeds. A couple tests seem to fail with this (stuff manipulating the environment expecting no collisions, for example), or become pointless (all inputs to a function become equivalent). In these cases I've done a (gross) dance (ab)using `RandomState` and `Location::caller()` for some extra "entropy". Trying to share that code seems *way* more painful than it's worth given that the duplication is a 7-line function, even if the lines are quite gross. (Keeping in mind that sharing it would require adding `rand` as a non-dev dep to std, and exposing a type from it publicly, all of which sounds truly awful, even if done behind a perma-unstable feature). See also some previous attempts: - https://github.com/rust-lang/rust/pull/86963 (in particular https://github.com/rust-lang/rust/pull/86963#issuecomment-885438936 which explains why this is non-trivial) - https://github.com/rust-lang/rust/pull/89131 - https://github.com/rust-lang/rust/pull/96626#issuecomment-1114562857 (I tried in that PR at the same time, but settled for just removing the usage of `thread_rng()` from the benchmarks, since that was the main goal). - https://github.com/rust-lang/rust/pull/104185 - Probably more. It's very tempting of a thing to "just update". r? `@Mark-Simulacrum`
2023-01-08Remove unnecessary lseek syscall when using std::fs::readyukang-2/+6
2023-01-07docs: make `HashSet::retain` doctest more clearEzra Shaw-1/+1
2023-01-04Update rand in the stdlib tests, and remove the getrandom feature from itThom Chiovoloni-10/+39
2023-01-04docs: fix broken link "search bar"Michael Howell-1/+1
2023-01-04Rollup merge of #106327 - gimbles:dbg, r=jyn514Matthias Krüger-0/+1
Add tidy check for dbg Fixes #106169
2023-01-03Rollup merge of #106045 - RalfJung:oom-nounwind-panic, r=AmanieuMichael Goulet-1/+1
default OOM handler: use non-unwinding panic, to match std handler The OOM handler in std will by default abort. This adjusts the default in liballoc to do the same, using the `can_unwind` flag on the panic info to indicate a non-unwinding panic. In practice this probably makes little difference since the liballoc default will only come into play in no-std situations where people write a custom panic handler, which most likely will not implement unwinding. But still, this seems more consistent. Cc `@rust-lang/wg-allocators,` https://github.com/rust-lang/rust/issues/66741
2023-01-02Rollup merge of #104298 - tbu-:pr_set_extension_caveats, r=m-ou-seMichael Goulet-3/+30
Add notes and examples about non-intuitive `PathBuf::set_extension` behavior Basically, passing the empty string will actually remove the extension instead of setting it to the empty string. This might change what is considered to be an extension. Additionally, passing an extension that contains dots will make the path only consider the last part of it to be the new extension.
2023-01-02default OOM handler: use non-unwinding panic (unless -Zoom=panic is set), to ↵Ralf Jung-1/+1
match std handler
2023-01-01Document a way to limit read_line lengthKornel-2/+3
2023-01-01Document read_line gotchaKornel-2/+5
2022-12-31Rollup merge of #106280 - Ezrashaw:path-join-docs-better, r=thomccMatthias Krüger-0/+3
docs: add link to `Path::join` in `PathBuf::push` Fixes #106219 Hopefully my wording is alright.
2022-12-31Add tidy check for dbggimbles-0/+1
2022-12-30Rollup merge of #105903 - joboet:unify_parking, r=m-ou-seMichael Goulet-240/+207
Unify id-based thread parking implementations Multiple platforms currently use thread-id-based parking implementations (NetBSD and SGX[^1]). Even though the strategy does not differ, these are duplicated for each platform, as the id is encoded into an atomic thread variable in different ways for each platform. Since `park` is only called by one thread, it is possible to move the thread id into a separate field. By ensuring that the field is only written to once, before any other threads access it, these accesses can be unsynchronized, removing any restrictions on the size and niches of the thread id. This PR also renames the internal `thread_parker` modules to `thread_parking`, as that name now better reflects their contents. I hope this does not add too much reviewing noise. r? `@m-ou-se` `@rustbot` label +T-libs [^1]: SOLID supports this as well, I will switch it over in a follow-up PR.
2022-12-31Add notes and examples about non-intuitive `PathBuf::set_extension` behaviorTobias Bucher-3/+30
Basically, passing the empty string will actually remove the extension instead of setting it to the empty string. This might change what is considered to be an extension. Additionally, passing an extension that contains dots will make the path only consider the last part of it to be the new extension.
2022-12-30Auto merge of #105651 - tgross35:once-cell-inline, r=m-ou-sebors-1/+21
Add #[inline] markers to once_cell methods Added inline markers to all simple methods under the `once_cell` feature. Relates to #74465 and #105587 This should not block #105587
2022-12-30Auto merge of #106296 - matthiaskrgr:rollup-ukdbqwx, r=matthiaskrgrbors-29/+37
Rollup of 4 pull requests Successful merges: - #99244 (doc: clearer and more correct Iterator::scan) - #103707 (Replace libstd, libcore, liballoc terminology in docs) - #104182 (`IN6ADDR_ANY_INIT` and `IN6ADDR_LOOPBACK_INIT` documentation.) - #106273 (rustdoc: remove redundant CSS `.source .content { overflow: visible }`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-12-30Rollup merge of #104182 - gabhijit:ipv6-in6addr-any-doc-fix, r=m-ou-seMatthias Krüger-0/+9
`IN6ADDR_ANY_INIT` and `IN6ADDR_LOOPBACK_INIT` documentation. Added documentation for IPv6 Addresses `IN6ADDR_ANY_INIT` also known as `in6addr_any` and `IN6ADDR_LOOPBACK_INIT` also known as `in6addr_loopback` similar to `INADDR_ANY` for IPv4 Addresses.
2022-12-30std: remove unnecessary `#[cfg]` on NetBSDjoboet-2/+0
2022-12-30std: rename `Parker::new` to `Parker::new_in_place`, add safe `Parker::new` ↵joboet-24/+16
constructor for SGX
2022-12-30Replace libstd, libcore, liballoc in line comments.jonathanCogan-16/+16
2022-12-30Replace libstd, libcore, liballoc in docs.jonathanCogan-13/+12
2022-12-30Auto merge of #105426 - flba-eb:fix_tls_destructor_unwinding, r=m-ou-sebors-7/+14
Catch panics/unwinding in destruction of TLS values `destroy_value` is/can be called from C code (libc). Unwinding from Rust to C code is undefined behavior, which is why unwinding is caught here. This problem caused an infinite loop inside the unwinding code when running `src/test/ui/threads-sendsync/issue-24313.rs` on a tier 3 target (QNX/Neutrino) on aarch64. See also https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Infinite.20unwinding.20bug.
2022-12-30docs: add link to `Path::join` in `PathBuf::push`Ezra Shaw-0/+3
2022-12-29std: pass hint to id-based parking functionsjoboet-13/+13
2022-12-29std: unify id-based thread parking implementationsjoboet-231/+208
2022-12-29Auto merge of #105590 - solid-rs:patch/kmc-solid/thread-lifecycle-ordering, ↵bors-9/+16
r=m-ou-se kmc-solid: Fix memory ordering in thread operations Fixes two memory ordering issues in the thread state machine (`ThreadInner::lifecycle`) of the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. 1. When detaching a thread that is still running (i.e., the owner updates `lifecycle` first, and the child updates it next), the first update did not synchronize-with the second update, resulting in a data race between the first update and the deallocation of `ThreadInner` by the child thread. 2. When joining on a thread, the joiner has to pass its own task ID to the joinee in order to be woken up later, but in doing so, it did not synchronize-with the read operation, creating possible sequences of execution where the joinee wakes up an incorrect or non-existent task. Both issue are theoretical and most likely have never manifested in practice because of the stronger guarantees provided by the Arm memory model (particularly due to its barrier-based definition). Compiler optimizations could have subverted this, but the inspection of compiled code did not reveal such optimizations taking place.
2022-12-29Auto merge of #105741 - pietroalbini:pa-1.68-nightly, r=Mark-Simulacrumbors-69/+10
Bump master bootstrap compiler This PR bumps the bootstrap compiler to the beta created earlier this week, cherry-picks the stabilization version number updates, and updates the `cfg(bootstrap)`s. r? `@Mark-Simulacrum`
2022-12-28Rollup merge of #105998 - RalfJung:no-unwind-panic-msg, r=thomccMatthias Krüger-1/+5
adjust message on non-unwinding panic "thread panicked while panicking" is just plain wrong in case this is a non-unwinding panic, such as - a panic out of a `nounwind` function - the sanity checks we have in `mem::uninitialized` and `mem::zeroed` - the optional debug assertion in various unsafe std library functions
2022-12-28Rollup merge of #105497 - albertlarsan68:doc-panic-hook-and-catch-unwind, ↵Matthias Krüger-0/+3
r=m-ou-se Clarify `catch_unwind` docs about panic hooks Makes it clear from `catch_unwind` docs that the panic hook will be called before the panic is caught. Fixes #105432
2022-12-28Rollup merge of #105359 - flba-eb:thread_local_key_sentinel_value, r=m-ou-seMatthias Krüger-8/+17
Make sentinel value configurable in `library/std/src/sys_common/thread_local_key.rs` This is an excerpt of a changeset for the QNX/Neutrino OS. To make the patch for QNX smaller and easier to review, I've extracted this change (which is OS independent). I would be surprised if no other OS is also affected. All this patch does is to define a `const` for a sentinel value instead of using it directly at several places. There are OSs that always return the lowest free value. The algorithm in `lazy_init` always avoids keys with the sentinel value. In affected OSs, this means that each call to `lazy_init` will always request two keys from the OS and returns/frees the first one (with sentinel value) immediately afterwards. By making the sentinel value configurable, affected OSs can use a different value than zero to prevent this performance issue. On QNX/Neutrino, it is planned to use a different sentinel value: ```rust // Define a sentinel value that is unlikely to be returned // as a TLS key (but it may be returned). #[cfg(not(target_os = "nto"))] const KEY_SENTVAL: usize = 0; // On QNX/Neutrino, 0 is always returned when currently not in use. // Using 0 would mean to always create two keys and remote the first // one (with value of 0) immediately afterwards. #[cfg(target_os = "nto")] const KEY_SENTVAL: usize = libc::PTHREAD_KEYS_MAX + 1; ``` It seems like no other OS defines `PTHREAD_KEYS_MAX` in Rusts libc, but `limits.h` on unix systems does.
2022-12-28Rollup merge of #104493 - adamncasey:cgroupzeroperiod, r=m-ou-seMatthias Krüger-2/+2
available_parallelism: Gracefully handle zero value cfs_period_us There seem to be some scenarios where the cgroup cpu quota field `cpu.cfs_period_us` can contain `0`. This field is used to determine the "amount" of parallelism suggested by the function `std::thread::available_parallelism` A zero value of this field cause a panic when `available_parallelism()` is invoked. This issue was detected by the call from binaries built by `cargo test`. I really don't feel like `0` is a good value for `cpu.cfs_period_us`, but I also don't think applications should panic if this value is seen. This panic started happening with rust 1.64.0. This case is gracefully handled by other projects which read this information: [num_cpus](https://github.com/seanmonstar/num_cpus/blob/e437b9d9083d717692e35d917de8674a7987dd06/src/linux.rs#L207-L210), [ninja](https://github.com/ninja-build/ninja/pull/2174/files), [dotnet](https://github.com/dotnet/runtime/blob/c4341d45acca3ea662cd8d71e7d71094450dd045/src/coreclr/pal/src/misc/cgroup.cpp#L481-L483) Before this change, running `cargo test` in environments configured as described above would trigger this panic: ``` $ RUST_BACKTRACE=1 cargo test Finished test [unoptimized + debuginfo] target(s) in 3.55s Running unittests src/main.rs (target/debug/deps/x-9a42e145aca2934d) thread 'main' panicked at 'attempt to divide by zero', library/std/src/sys/unix/thread.rs:546:70 stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: std::sys::unix::thread::cgroups::quota 4: std::sys::unix::thread::available_parallelism 5: std::thread::available_parallelism 6: test::helpers::concurrency::get_concurrency 7: test::console::run_tests_console 8: test::test_main 9: test::test_main_static 10: x::main at ./src/main.rs:1:1 11: core::ops::function::FnOnce::call_once at /tmp/rust-1.64-1.64.0-1/library/core/src/ops/function.rs:248:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. error: test failed, to rerun pass '--bin x' ``` I've tested this change in an environment which has the bad (questionable?) setup and rebuilding the test executable against a fixed std library fixes the panic.
2022-12-28Rollup merge of #104402 - joboet:sync_remutex, r=m-ou-seMatthias Krüger-4/+5
Move `ReentrantMutex` to `std::sync` If I understand #84187 correctly, `sys_common` should not contain platform-independent code, even if it is private.
2022-12-28Catch panics in destruction of TLS valuesFlorian Bartels-7/+14
`destroy_value` is/can be called from C code (libc). Unwinding from Rust to C code is undefined behavior, which is why unwinding is caught here.
2022-12-28Clarify catch_unwind docs about panic hooksAlbert Larsan-0/+3
Makes it clear from catch_unwind docs that the panic hook will be called before the panic is caught.
2022-12-28delete more `cfg(bootstrap)`Lukas Markeffsky-18/+6
2022-12-28Update bootstrap cfgPietro Albini-51/+4
2022-12-28adjust message on non-unwinding panicRalf Jung-1/+5
2022-12-28Rollup merge of #104708 - ↵fee1-dead-1/+1
jonasspinner:fix-backoff-doc-to-match-implementation, r=compiler-errors Fix backoff doc to match implementation The commit 8dddb2294310ad3e8ce0b2af735a702ad72a9a99 in the crossbeam-channel PR (#93563) changed the backoff strategy to be quadratic instead of exponential. This updates the doc to prevent confusion.
2022-12-28Auto merge of #100539 - joboet:horizon_timeout_clock, r=thomccbors-2/+4
Use correct clock in `park_timeout` on Horizon Horizon does not support using `CLOCK_MONOTONIC` with condition variables, so use the system time instead.
2022-12-27Auto merge of #106193 - compiler-errors:rollup-0l54wka, r=compiler-errorsbors-4/+7
Rollup of 9 pull requests Successful merges: - #103718 (More inference-friendly API for lazy) - #105765 (Detect likely `.` -> `..` typo in method calls) - #105852 (Suggest rewriting a malformed hex literal if we expect a float) - #105965 (Provide local extern function arg names) - #106064 (Partially fix `explicit_outlives_requirements` lint in macros) - #106179 (Fix a formatting error in Iterator::for_each docs) - #106181 (Fix doc comment parsing description in book) - #106187 (Update the documentation of `Vec` to use `extend(array)` instead of `extend(array.iter().copied())`) - #106189 (Fix UnsafeCell Documentation Spelling Error) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-12-27Rollup merge of #103718 - matklad:infer-lazy, r=dtolnayMichael Goulet-4/+7
More inference-friendly API for lazy The signature for new was ``` fn new<F>(f: F) -> Lazy<T, F> ``` Notably, with `F` unconstrained, `T` can be literally anything, and just `let _ = Lazy::new(|| 92)` would not typecheck. This historiacally was a necessity -- `new` is a `const` function, it couldn't have any bounds. Today though, we can move `new` under the `F: FnOnce() -> T` bound, which gives the compiler enough data to infer the type of T from closure.
2022-12-27Auto merge of #97176 - kraktus:cmd_debug, r=the8472bors-8/+173
More verbose `Debug` implementation of `std::process:Command` Mainly based on commit: https://github.com/zackmdavis/rust/commit/ccc019aabfdd550944c049625e66c92c815ea1d0 from https://github.com/zackmdavis close https://github.com/rust-lang/rust/issues/42200