about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2024-06-04Rollup merge of #125932 - schvv31n:patch-1, r=lqdGuillaume Gomez-1/+1
Fix typo in the docs of `HashMap::raw_entry_mut` <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> -->
2024-06-04Rollup merge of #125696 - workingjubilee:please-dont-say-you-are-lazy, ↵Guillaume Gomez-59/+73
r=Nilstrieb Explain differences between `{Once,Lazy}{Cell,Lock}` types The question of "which once-ish cell-ish type should I use?" has been raised multiple times, and is especially important now that we have stabilized the `LazyCell` and `LazyLock` types. The answer for the `Lazy*` types is that you would be better off using them if you want to use what is by far the most common pattern: initialize it with a single nullary function that you would call at every `get_or_init` site. For everything else there's the `Once*` types. "For everything else" is a somewhat weak motivation, as it only describes by negation. While contrasting them is inevitable, I feel positive motivations are more understandable. For this, I now offer a distinct example that helps explain why `OnceLock` can be useful, despite `LazyLock` existing: you can do some cool stuff with it that `LazyLock` simply can't support due to its mere definition. The pair of `std::sync::*Lock`s are usable inside a `static`, and can serve roles in async or multithreaded (or asynchronously multithreaded) programs that `*Cell`s cannot. Because of this, they received most of my attention. Fixes #124696 Fixes #125615
2024-06-04Rollup merge of #125919 - tbu-:pr_fix_typo, r=lqd许杰友 Jieyou Xu (Joe)-2/+1
Remove stray "this"
2024-06-04Rollup merge of #125504 - mqudsi:once_nominal, r=cuviper许杰友 Jieyou Xu (Joe)-1/+1
Change pedantically incorrect OnceCell/OnceLock wording While the semantic intent of a OnceCell/OnceLock is that it can only be written to once (upon init), the fact of the matter is that both these types offer a `take(&mut self) -> Option<T>` mechanism that, when successful, resets the cell to its initial state, thereby [technically allowing it to be written to again](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=415c023a6ae1ef35f371a2d3bb1aa735) Despite the fact that this can only happen with a mutable reference (generally only used during the construction of the OnceCell/OnceLock), it would be incorrect to say that the type itself as a whole *categorically* prevents being initialized or written to more than once (since it is possible to imagine an identical type only without the `take()` method that actually fulfills that contract). To clarify, change "that cannot be.." to "that nominally cannot.." and add a note to OnceCell about what can be done with an `&mut Self` reference. ```@rustbot``` label +A-rustdocs
2024-06-04Auto merge of #125525 - joboet:tls_accessor, r=cuviperbors-180/+107
Make TLS accessors closures that return pointers The current TLS macros generate a function that returns an `Option<&'static T>`. This is both risky as we lie about lifetimes, and necessitates that those functions are `unsafe`. By returning a `*const T` instead, the accessor function do not have safety requirements any longer and can be made closures without hassle. This PR does exactly that! For native TLS, the closure approach makes it trivial to select the right accessor function at compile-time, which could result in a slight speed-up (I have the hope that the accessors are now simple enough for the MIR-inliner to kick in).
2024-06-03Fix typo in the docs of `HashMap::raw_entry_mut`Tim Kurdov-1/+1
2024-06-03Remove stray "this"Tobias Bucher-2/+1
2024-06-02Add "OnceList" example to motivate OnceLockJubilee Young-0/+55
While slightly verbose, it helps explain "why bother with OnceLock?" This is a point of confusion that has been raised multiple times shortly before and after the stabilization of LazyLock.
2024-06-02Move first OnceLock example to LazyLockJubilee Young-58/+14
This example is spiritually an example of LazyLock, as it computes a variable at runtime but accepts no inputs into that process. It is also slightly simpler and thus easier to understand. Change it to an even-more concise version and move it to LazyLock. The example now editorializes slightly more. This may be unnecessary, but it can be educational for the reader.
2024-06-02Differ LazyLock vs. OnceLock in std::sync overviewJubilee Young-1/+4
2024-06-02Rollup merge of #125898 - RalfJung:typo, r=NilstriebJubilee-1/+1
typo: depending from -> on
2024-06-02typo: depending from -> onRalf Jung-1/+1
2024-06-02Auto merge of #125577 - devnexen:netbsd_stack_min, r=joboetbors-1/+10
std::pal::unix::thread fetching min stack size on netbsd. PTHREAD_STACK_MIN is not defined however sysconf/_SC_THREAD_STACK_MIN returns it as it can vary from arch to another.
2024-05-30Auto merge of #124636 - tbu-:pr_env_unsafe, r=petrochenkovbors-69/+95
Make `std::env::{set_var, remove_var}` unsafe in edition 2024 Allow calling these functions without `unsafe` blocks in editions up until 2021, but don't trigger the `unused_unsafe` lint for `unsafe` blocks containing these functions. Fixes #27970. Fixes #90308. CC #124866.
2024-05-30Rollup merge of #125342 - tbu-:pr_doc_write, r=ChrisDentonMatthias Krüger-0/+76
Document platform-specifics for `Read` and `Write` of `File`
2024-05-29Elaborate about modifying env vars in multi-threaded programsTobias Bucher-18/+28
2024-05-29Add note about safety of `std::env::set_var` on WindowsTobias Bucher-5/+11
2024-05-29Make `std::env::{set_var, remove_var}` unsafe in edition 2024Tobias Bucher-53/+63
Allow calling these functions without `unsafe` blocks in editions up until 2021, but don't trigger the `unused_unsafe` lint for `unsafe` blocks containing these functions. Fixes #27970. Fixes #90308. CC #124866.
2024-05-29Rollup merge of #125226 - madsmtm:fix-mac-catalyst-tests, r=workingjubilee许杰友 Jieyou Xu (Joe)-1/+9
Make more of the test suite run on Mac Catalyst Combined with https://github.com/rust-lang/rust/pull/125225, the only failing parts of the test suite are in `tests/rustdoc-js`, `tests/rustdoc-js-std` and `tests/debuginfo`. Tested with: ```console ./x test --target=aarch64-apple-ios-macabi library/std ./x test --target=aarch64-apple-ios-macabi --skip=tests/rustdoc-js --skip=tests/rustdoc-js-std --skip=tests/debuginfo tests ``` Will probably put up a PR later to enable _running_ on (not just compiling for) Mac Catalyst in CI, though not sure where exactly I should do so? `src/ci/github-actions/jobs.yml`? Note that I've deliberately _not_ enabled stack overflow handlers on iOS/tvOS/watchOS/visionOS (see https://github.com/rust-lang/rust/issues/25872), but rather just skipped those tests, as it uses quite a few APIs that I'd be weary about getting rejected by the App Store (note that Swift doesn't do it on those platforms either). r? ``@workingjubilee`` CC ``@thomcc`` ``@rustbot`` label O-ios O-apple
2024-05-28Make more of the test suite run on Mac CatalystMads Marquart-1/+1
This adds the `only-apple`/`ignore-apple` compiletest directive, and uses that basically everywhere instead of `only-macos`/`ignore-macos`. Some of the updates in `run-make` are a bit redundant, as they use `ignore-cross-compile` and won't run on iOS - but using Apple in these is still more correct, so I've made that change anyhow.
2024-05-28Disable stack overflow handler tests on iOS-like platformsMads Marquart-0/+8
2024-05-28update tracking issue for lazy_cell_consumeTrevor Spiteri-1/+1
2024-05-26Auto merge of #122079 - tbu-:pr_copy_file_range_probe, r=the8472bors-19/+48
Less syscalls for the `copy_file_range` probe If it's obvious from the actual syscall results themselves that the syscall is supported or unsupported, don't do an extra syscall with an invalid file descriptor. CC #122052
2024-05-26std::pal::unix::thread fetching min stack size on netbsd.David Carlier-1/+10
PTHREAD_STACK_MIN is not defined however sysconf/_SC_THREAD_STACK_MIN returns it as it can vary from arch to another.
2024-05-26Auto merge of #125070 - tbu-:pr_set_extension_panic, r=jhprattbors-0/+36
Panic if `PathBuf::set_extension` would add a path separator This is likely never intended and potentially a security vulnerability if it happens. I'd guess that it's mostly literal strings that are passed to this function in practice, so I'm guessing this doesn't break anyone. CC #125060
2024-05-25std: make TLS accessors closures that return pointersjoboet-180/+107
2024-05-24Change pedantically incorrect OnceCell/OnceLock wordingMahmoud Al-Qudsi-1/+1
While the semantic intent of a OnceCell/OnceLock is that it can only be written to once (upon init), the fact of the matter is that both these types offer a `take(&mut self) -> Option<T>` mechanism that, when successful, resets the cell to its initial state, thereby technically allowing it to be written to again. Despite the fact that this can only happen with a mutable reference (generally only used during the construction of the OnceCell/OnceLock), it would be incorrect to say that the type itself as a whole categorically prevents being initialized or written to more than once (since it is possible to imagine an identical type only without the `take()` method that actually fulfills that contract). To clarify, change "that cannot be.." to "that nominally cannot.." and add a note to OnceCell about what can be done with an `&mut Self` reference.
2024-05-24std: clean up the TLS implementationjoboet-5/+4
2024-05-24std: simplify key-based thread localsjoboet-185/+60
2024-05-24Auto merge of #125463 - GuillaumeGomez:rollup-287wx4y, r=GuillaumeGomezbors-2/+2
Rollup of 6 pull requests Successful merges: - #125263 (rust-lld: fallback to rustc's sysroot if there's no path to the linker in the target sysroot) - #125345 (rustc_codegen_llvm: add support for writing summary bitcode) - #125362 (Actually use TAIT instead of emulating it) - #125412 (Don't suggest adding the unexpected cfgs to the build-script it-self) - #125445 (Migrate `run-make/rustdoc-with-short-out-dir-option` to `rmake.rs`) - #125452 (Cleanup check-cfg handling in core and std) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-24Auto merge of #123724 - joboet:static_tls, r=m-ou-sebors-70/+76
Rewrite TLS on platforms without threads The saga of #110897 continues! r? `@m-ou-se` if you have time
2024-05-23Rollup merge of #125452 - Urgau:check-cfg-libraries-cleanup, r=bjorn3Guillaume Gomez-2/+2
Cleanup check-cfg handling in core and std Follow-up to https://github.com/rust-lang/rust/pull/125296 where we: - expect any feature cfg in std, due to `#[path]` imports - move some check-cfg args inside the `build.rs` as per Cargo recommendation - and replace the fake Cargo feature `"restricted-std"` by the custom cfg `restricted_std` Fixes https://github.com/rust-lang/rust/pull/125296#issuecomment-2127009301 r? `@bjorn3` (maybe, feel free to re-roll)
2024-05-23Replace fake "restricted-std" Cargo feature by custom cfgUrgau-2/+2
2024-05-23std: rewrite native thread-local storagejoboet-249/+331
2024-05-21Rollup merge of #125348 - tbu-:pr_doc_path_absolute, r=jhprattMatthias Krüger-3/+6
Small fixes to `std::path::absolute` docs
2024-05-21Rollup merge of #125225 - madsmtm:ios-crt_externs.h, r=workingjubileeMatthias Krüger-150/+127
Use functions from `crt_externs.h` on iOS/tvOS/watchOS/visionOS Use `_NSGetEnviron`, `_NSGetArgc` and `_NSGetArgv` on iOS/tvOS/watchOS/visionOS, see each commit and the code comments for details. This allows us to unify more code with the macOS implementation, as well as avoiding linking to the `Foundation` framework (which is good for startup performance). The biggest problem with doing this would be if it lead to App Store rejections. After doing a bunch of research on this, while [it did happen once in 2009](https://blog.unity.com/engine-platform/unity-app-store-submissions-problem-solved), I find it fairly unlikely to happen nowadays, especially considering that Apple has later _added_ `crt_externs.h` to the iOS/tvOS/watchOS/visionOS SDKs, strongly signifying the functions therein is indeed supported on those platforms (even though they lack an availability attribute). That we've been overly cautious here has also been noted by `@thomcc` in https://github.com/rust-lang/rust/pull/117910#issuecomment-1903372350. r? `@workingjubilee` `@rustbot` label O-apple
2024-05-21Rollup merge of #125333 - hermit-os:fuse, r=workingjubileeMatthias Krüger-21/+4
switch to the default implementation of `write_vectored` HermitOS doesn't support write_vectored and switch to the default implementation of `write_vectored`.
2024-05-21Rollup merge of #125123 - a1phyr:fix-read_exact, r=workingjubileeMatthias Krüger-10/+55
Fix `read_exact` and `read_buf_exact` for `&[u8]` and `io:Cursor` - Drain after `read_exact` and `read_buf_exact` - Append to cursor in `read_buf_exact`
2024-05-21Small fixes to `std::path::absolute` docsTobias Bucher-3/+6
2024-05-20switch also the default implementation for read_vectoredStefan Lankes-13/+2
2024-05-20Document platform-specifics for `Read` and `Write` of `File`Tobias Bucher-0/+76
2024-05-20switch to the default implementation of `write_vectored`Stefan Lankes-8/+2
2024-05-20Remove Windows dependency on libcBen Kimock-0/+3
2024-05-20Address review commentsBenoît du Garreau-1/+33
2024-05-20Make NULL check in argument parsing the same on all unix platformsMads Marquart-76/+64
2024-05-19Rollup merge of #124992 - foresterre:example/is-terminal, r=ChrisDentonMatthias Krüger-0/+34
Add example to IsTerminal::is_terminal
2024-05-19Add example to IsTerminal::is_terminalMartijn-0/+34
2024-05-19Rollup merge of #124304 - hermit-os:fuse, r=joboetMichael Goulet-90/+87
revise the interpretation of ReadDir for HermitOS HermitOS supports getdents64. As under Linux, the dirent64 entry `d_off` is not longer used, because its definition is not clear. Instead of `d_off` the entry `d_reclen` is used to determine the end of the dirent64 entry. In addition, take up `@workingjubilee` suggestion from the discussions in rust-lang/rust#115984 to increase the readability. Hermit is a tier 3 platform and this PR changes only files, wich are related to the tier 3 platform.
2024-05-19Rollup merge of #123709 - tgross35:windows-cmd-docs-update, r=ChrisDentonMichael Goulet-38/+59
Update documentation related to the recent cmd.exe fix Fix some grammar nits, change `bat` (extension) -> `batch` (file), and make line wrapping more consistent.
2024-05-19Add NULL check in argument parsing on Apple platformsMads Marquart-14/+44