about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
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-30Avoid `mut` and simplify initialization of `TASK_QUEUE`Raoul Strackx-9/+5
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-21Simplify environment variable examplesMartin Geisler-10/+4
I’ve found myself visiting the documentation for `std::env::vars` every few months, and every time I do, it is because I want to quickly get a snippet to print out all environment variables :-) So I think it could be nice to simplify the examples a little to make them self-contained. It is of course a style question if one should import a module a not, but I personally don’t import modules used just once in a code snippet.
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-21Document behavior of `create_dir_all` wrt. empty pathTobias Bucher-0/+3
The behavior makes sense because `Path::new("one_component").parent() == Some(Path::new(""))`, so if one naively wants to create the parent directory for a file to be written, it simply works. Closes #105108 by documenting the current behavior.
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
2024-05-18android: use posix_memalign for aligned allocationsRalf Jung-18/+1
2024-05-17Use `_NSGetArgc`/`_NSGetArgv` on iOS/tvOS/watchOS/visionOSMads Marquart-84/+19
If we're comfortable using `_NSGetEnviron` from `crt_externs.h`, there shouldn't be an issue with using these either, and then we can merge with the macOS implementation. This also fixes two test cases on Mac Catalyst: - `tests/ui/command/command-argv0.rs`, maybe because `[[NSProcessInfo processInfo] arguments]` somehow converts the name of the first argument? - `tests/ui/env-funky-keys.rs` since we no longer link to Foundation.
2024-05-17Use `_NSGetEnviron` instead of `environ` on iOS/tvOS/watchOS/visionOSMads Marquart-2/+26
This should be slightly more correct, and matches the implementation in other programming languages: - [Python's `os.environ`](https://github.com/python/cpython/blob/v3.12.3/Modules/posixmodule.c#L1562-L1566). - [Swift's `Darwin.environ`](https://github.com/apple/swift-corelibs-foundation/blob/swift-5.10-RELEASE/CoreFoundation/Base.subproj/CFPlatform.c#L1811-L1812), though that library is bundled on the system, so they can change it if they want. - [Dart/Flutter](https://github.com/dart-lang/sdk/blob/3.4.0/runtime/bin/platform_macos.cc#L205-L234), doesn't support environment variables on iOS. - Node seems to not be entirely consistent with it: - [`process.c`](https://github.com/nodejs/node/blob/v22.1.0/deps/uv/src/unix/process.c#L38). - [`unix/core.c`](https://github.com/nodejs/node/blob/v22.1.0/deps/uv/src/unix/core.c#L59). - [.NET/Xamarin](https://github.com/dotnet/runtime/blob/v8.0.5/src/native/libs/configure.cmake#L1099-L1106). - [OpenJDK](https://github.com/openjdk/jdk/blob/jdk-23%2B22/src/java.base/unix/native/libjava/ProcessEnvironment_md.c#L31-L33).
2024-05-16Add `powi` to `f16` and `f128`Trevor Gross-0/+48
This will unblock adding support to compiler_builtins (<https://github.com/rust-lang/compiler-builtins/pull/614>), which will then unblock adding tests for these new functions.
2024-05-15Rollup merge of #125003 - RalfJung:aligned_alloc, r=cuviperLeón Orell Valerian Liehr-11/+8
avoid using aligned_alloc; posix_memalign is better-behaved Also there's no reason why wasi should be different than all the other Unixes here.