about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2025-06-07Rollup merge of #137992 - its-the-shrimp:stabilise_os_string_pathbuf_leak, ↵Jacob Pratt-2/+2
r=dtolnay Stabilise `os_string_pathbuf_leak` This PR stabilises `#[feature(os_string_pathbuf_leak)]`, which defines 2 new methods in the std: ```rs impl OsString { pub fn leak<'a>(self) -> &'a mut OsStr; } impl PathBuf { pub fn leak<'a>(self) -> &'a mut Path; } ``` ACP: https://github.com/rust-lang/libs-team/issues/389 Tracking issue: https://github.com/rust-lang/rust/issues/125965 Implementation: https://github.com/rust-lang/rust/pull/125966
2025-06-06Rollup merge of #141471 - RalfJung:unsafe-fn-in-trait, r=traviscrossGuillaume Gomez-16/+11
unsafe keyword docs: emphasize that an unsafe fn in a trait does not get to choose its safety contract Inspired by discussion in https://github.com/rust-lang/rust/issues/139368. Cc `@hanna-kruppe`
2025-06-06Rollup merge of #140418 - tgross35:std-c-size_t, r=workingjubileeGuillaume Gomez-0/+2
Reexport types from `c_size_t` in `std` These are unstably available in `core` and should be in `std` too, but are not currently reexported. Resolve this here. Tracking issue: https://github.com/rust-lang/rust/issues/88345
2025-06-06unsafe keyword docs: emphasize that an unsafe fn in a trait does not get to ↵Ralf Jung-16/+11
choose its safety contract
2025-06-06Stabilised `os_string_pathbuf_leak`schvv31n-2/+2
2025-06-06std: sys: random: uefi: Provide rdrand based fallbackAyush Singh-19/+150
Some UEFI systems based on American Megatrends Inc. v3.3 do not provide RNG support [1]. So fallback to rdrand in such cases. [1]: https://github.com/rust-lang/rust/issues/138252#issuecomment-2891270323 Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-06-06Add new Tier-3 targets: `loongarch32-unknown-none*`WANG Rui-1/+4
MCP: https://github.com/rust-lang/compiler-team/issues/865
2025-06-06Rollup merge of #142091 - thaliaarchi:aix-getenv, r=workingjubileeMatthias Krüger-1/+1
Fix AIX build Fix rust-lang/rust#141543. `getenv` was moved out of this file to `sys::env::getenv` in rust-lang/rust#140143. Replace its usage with `std::env::var_os`, the publicly exposed version. This matches the other usages of the same function in this file.
2025-06-05Fix AIX buildThalia Archibald-1/+1
2025-06-05Clarify description of `Seek::stream_len`Tobias Bucher-1/+1
It can only describe the inner workings of the default implementation, other implementations might not be implemented using seeks at all.
2025-06-05Optimize `Seek::stream_len` impl for `File`Tobias Bucher-10/+89
It uses the file metadata on Unix with a fallback for files incorrectly reported as zero-sized. It uses `GetFileSizeEx` on Windows. This reduces the number of syscalls needed for determining the file size of an open file from 3 to 1.
2025-06-05change tests to use fixed constants to let them pass with miriLorrensP-2158466-20/+20
2025-06-04Rollup merge of #141467 - cyrgani:const-empty-stringlikes, r=AmanieuMatthias Krüger-5/+7
make `OsString::new` and `PathBuf::new` unstably const Since #129041, `String::into_bytes` is `const`, which allows making `OsString::new` and `PathBuf::new` unstably const now. Not sure what the exact process for this is; does it need an ACP?
2025-06-03Rollup merge of #141925 - cuviper:vestigial-bootstrap, r=workingjubileeMatthias Krüger-8/+2
Remove bootstrap cfgs from library/ These `cfg(bootstrap)` are always false now that rust-lang/rust#119899 has landed, and likewise `cfg(not(bootstrap))` is always true. Therefore, we don't need to wait for the usual stage0 bump to clean these up.
2025-06-03Rollup merge of #141455 - joboet:tls_exhaustion_abort, r=tgross35Matthias Krüger-11/+10
std: abort the process on failure to allocate a TLS key The panic machinery uses TLS, so panicking if no TLS keys are left can lead to infinite recursion (see https://github.com/rust-lang/rust/issues/140798#issuecomment-2872307377). Rather than having separate logic for the panic count and the thread name, just always abort the process if a TLS key allocation fails. This also has the benefit of aligning the key-based TLS implementation with the documentation, which does not mention that a panic could also occur because of resource exhaustion.
2025-06-03Enable Float non-determinism in miri. Update and add tests and changeLorrensP-2158466-18/+18
change tests in std, core and coretests.
2025-06-03Rollup merge of #140715 - lukaslueg:oncecellsyncdocs, r=tgross35Matthias Krüger-5/+13
Clarify &mut-methods' docs on sync::OnceLock Three small changes to the docs of `sync::OnceLock`: * The docs for `OnceLock::take()` used to [say](https://doc.rust-lang.org/std/sync/struct.OnceLock.html#method.take) "**Safety** is guaranteed by requiring a mutable reference." (emphasis mine). While technically correct, imho its not necessary to even mention safety - as opposed to unsafety - here: Safety never comes up wrt `OnceLock`, as there is (currently) no way to interact with a `OnceLock` in an unsafe way; there are no unsafe methods on `OnceLock`, so there is "safety" guarantee required anywhere. What we simply meant to say is "**Synchronization** is guaranteed...". * I've add that phrase to the other methods of `OnceLock` which take a `&mut self`, to highlight the fact that having a `&mut OnceLock` guarantees that synchronization with other threads is not required. This is the same as with [`Mutex::get_mut()`](https://doc.rust-lang.org/std/sync/struct.Mutex.html#method.get_mut), [`Cell::get_mut()`](https://doc.rust-lang.org/std/cell/struct.Cell.html#method.get_mut), and others. * In that spirit, the half-sentence "or being initialized" was removed from `get_mut()`, as there is no way that the `OnceLock` is being initialized while we are holding `&mut` to it. Probably a copy&paste from `.get()`
2025-06-02Remove more library bootstrapJosh Stone-6/+1
2025-06-02Remove bootstrap cfgs from library/Josh Stone-2/+1
2025-06-02Explain TOCTOU on the top of `std::fs`, and ref it in functionsxizheyin-15/+41
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn> Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-01Rollup merge of #141832 - workingjubilee:explain-what-toctou-races-are, ↵Jacob Pratt-8/+19
r=thomcc,ChrisDenton library: explain TOCTOU races in `fs::remove_dir_all` In the previous description it said there was a TOCTOU race but did not explain exactly what the problem was. I sat down with the CVE, reviewed its text, and created this explanation. This context should hopefully help people understand the actual risk as-such. Incidentally, it also fixes the capitalization on the name of Redox OS. Original CVE and advisory: - CVE: https://www.cve.org/CVERecord?id=CVE-2022-21658 - security advisory: https://groups.google.com/g/rustlang-security-announcements/c/R1fZFDhnJVQ?pli=1 - github cross-post: https://github.com/rust-lang/rust/security/advisories/GHSA-r9cc-f5pr-p3j2
2025-05-31If HOME is empty, use the fallback insteadChris Denton-2/+5
2025-05-31library: explain TOCTOU races in `fs::remove_dir_all`Jubilee Young-8/+19
In the previous description it said there was a TOCTOU race but did not explain exactly what the problem was. I sat down with the CVE, reviewed its text, and created this explanation. This context should hopefully help people understand the actual risk as-such. Incidentally, it also fixes the capitalization on the name of Redox OS.
2025-05-31Add const support for float rounding methodsRuan Comelli-12/+25
Add const support for the float rounding methods floor, ceil, trunc, fract, round and round_ties_even. This works by moving the calculation logic from src/tools/miri/src/intrinsics/mod.rs into compiler/rustc_const_eval/src/interpret/intrinsics.rs. All relevant method definitions were adjusted to include the `const` keyword for all supported float types: f16, f32, f64 and f128. The constness is hidden behind the feature gate feature(const_float_round_methods) which is tracked in https://github.com/rust-lang/rust/issues/141555 This commit is a squash of the following commits: - test: add tests that we expect to pass when float rounding becomes const - feat: make float rounding methods `const` - fix: replace `rustc_allow_const_fn_unstable(core_intrinsics)` attribute with `#[rustc_const_unstable(feature = "f128", issue = "116909")]` in `library/core/src/num/f128.rs` - revert: undo update to `library/stdarch` - refactor: replace multiple `float_<mode>_intrinsic` rounding methods with a single, parametrized one - fix: add `#[cfg(not(bootstrap))]` to new const method tests - test: add extra sign tests to check `+0.0` and `-0.0` - revert: undo accidental changes to `round` docs - fix: gate `const` float round method behind `const_float_round_methods` - fix: remove unnecessary `#![feature(const_float_methods)]` - fix: remove unnecessary `#![feature(const_float_methods)]` [2] - revert: undo changes to `tests/ui/consts/const-eval/float_methods.rs` - fix: adjust after rebase - test: fix float tests - test: add tests for `fract` - chore: add commented-out `const_float_round_methods` feature gates to `f16` and `f128` - fix: adjust NaN when rounding floats - chore: add FIXME comment for de-duplicating float tests - test: remove unnecessary test file `tests/ui/consts/const-eval/float_methods.rs` - test: fix tests after upstream simplification of how float tests are run
2025-05-31Auto merge of #141685 - orlp:inplace-tls-drop, r=joboetbors-29/+51
Do not move thread-locals before dropping Fixes rust-lang/rust#140816. I also (potentially) improved the speed of `get_or_init` a bit by having an explicit hot/cold path. We still move the value before dropping in the event of a recursive initialization (leading to double-initialization with one value being silently dropped). This is the old behavior, but changing this to panic instead would involve changing tests and also the other OS-specific `thread_local/os.rs` implementation, which is more than I'd like in this PR.
2025-05-30Address review comments.Orson Peters-0/+7
2025-05-29Make `std/src/num` mirror `core/src/num`Trevor Gross-2/+8
The float modules in `std` are currently top-level but for `core`, they are nested within the `num` directory and referenced by `#[path = ...]`. For consistency, adjust `std` to use the same structure as `core`. Also change the `f16` and `f128` gates from outer attributes to inner attributes like `core` has.
2025-05-29Rollup merge of #141690 - Patrick-6:intercept-mutex, r=m-ou-seJacob Pratt-1/+13
Add `rustc_diagnostic_item` to `sys::Mutex` methods For an ongoing project for adding a concurrency model checker to Miri we need to be able to intercept locking/unlocking operations on standard library mutexes. This PR adds diagnostic items to the relevant calls `lock`, `try_lock` and `unlock` for the `sys::Mutex` implementation on the targets we care about. This PR also makes the internals of `pthread::Mutex` less public, to reduce the chance of anyone locking/unlocking a mutex without going through the intercepted methods. r? ``@RalfJung``
2025-05-29Rollup merge of #141477 - tshepang:patch-1, r=ChrisDentonJacob Pratt-5/+20
Path::with_extension: show that it adds an extension where one did no… …t exist I think the times I encountered this, I had to check first if files without extensions were added, since all examples only had files with existing extensions. Also, this replaced example already has a similar example below.
2025-05-29Rollup merge of #141104 - PaulDance:fix-win7-test_eq_windows_file_type, ↵Jacob Pratt-1/+23
r=ChrisDenton Test(fs): Fix `test_eq_windows_file_type` for Windows 7 Would otherwise fail on: ``` thread 'fs::tests::test_eq_windows_file_type' panicked at library/std/src/test_helpers.rs:53:20: called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: PermissionDenied, message: "Access is denied." } ``` This came from the read-only attribute set on the test file. In order to fix this, instead of simply disabling the test, the attribute is reset before the test's end so it may still run successfully. `@rustbot` label T-libs A-filesystem A-testsuite O-windows-7 O-windows-msvc
2025-05-28Clarify &mut-methods' docs on sync::OnceLockLukas Lueg-5/+13
2025-05-28When replacing an old value we may not drop it in placeOrson Peters-12/+8
2025-05-28Add same unsafe bound on get_or_init_slowOrson Peters-2/+8
2025-05-28Add comments to diagnostic itemsPatrick-6-0/+6
2025-05-28Do not panic, maintain old behaviorOrson Peters-25/+17
2025-05-28Rollup merge of #140697 - Sa4dUs:split-autodiff, r=ZuseZ4Trevor Gross-2/+5
Split `autodiff` into `autodiff_forward` and `autodiff_reverse` This PR splits `#[autodiff]` macro so `#[autodiff(df, Reverse, args)]` would become `#[autodiff_reverse(df, args)]` and `#[autodiff(df, Forward, args)]` would become `#[autodiff_forwad(df, args)]`.
2025-05-28Rollup merge of #140369 - jplatte:mutex-rwlock-data-ptr, r=AmanieuTrevor Gross-0/+33
Add data_ptr method to Mutex and RwLock Implementation of https://github.com/rust-lang/rust/issues/140368 / https://github.com/rust-lang/libs-team/issues/531. I tried to write a useful safety section about when it is safe to read or write through the returned pointers, but couldn't come up with something nice. Hoping this PR is still useful without that. I'm happy to add any doc strings other people come up with if needed before merge, of course. Unresolved questions: - Return a `LockResult` or not? - Return `*mut T` like existing APIs (`Cell::as_ptr` / `MaybeUninit::as[_mut]_ptr` / `Vec::as_ptr` / ...) or be more precise and return `NonNull<T>`?
2025-05-28Make pthread Mutex internals less publicPatrick-6-1/+1
2025-05-28Add diagnostic items to sys::MutexPatrick-6-0/+6
2025-05-28Improve safety comment, double-drop is not relevant hereOrson Peters-3/+4
2025-05-28Do not move thread-locals before droppingOrson Peters-32/+52
2025-05-28Test(fs): Fix test_eq_windows_file_type for Windows 7Paul Mabileau-1/+23
Would otherwise fail on: ``` thread 'fs::tests::test_eq_windows_file_type' panicked at library/std/src/test_helpers.rs:53:20: called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: PermissionDenied, message: "Access is denied." } ``` This came from the read-only attribute set on the test file. In order to fix this, instead of simply disabling the test, the attribute is reset before the test's end so it may still run successfully. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-27Rollup merge of #141312 - cberner:filelock_from, r=joshtriplettMatthias Krüger-8/+40
Add From<TryLockError> for io::Error Adds a `From` impl to make error propagation easier, as discussed in the tracking issue `TryLockError` is unstable under the "file_lock" feature. The related tracking issue is https://github.com/rust-lang/rust/issues/130994 This PR also cleanups the Windows implementation of `try_lock()` and `try_lock_shared()` as [discussed here](https://github.com/rust-lang/rust/pull/140718#discussion_r2076678485)
2025-05-26Rollup merge of #141472 - fluiderson:dev, r=workingjubileeJacob Pratt-2/+2
Attempt to improve the `std::fs::create_dir_all` docs related to atomicity The original paragraph was added in rust-lang/rust#124520. It doesn't match the actual code logic. It says "function returns an error" if "the parent components" _(which also implies directories)_ "have been created already". The code is as follows: https://github.com/rust-lang/rust/blob/e88e85463468ce5d5ce468414eb69e3b15fa8d42/library/std/src/fs.rs#L3146 https://github.com/rust-lang/rust/blob/e88e85463468ce5d5ce468414eb69e3b15fa8d42/library/std/src/fs.rs#L3160 These lines suppress all errors if any path component is a directory. I've updated the paragraph to mirror this.
2025-05-26Rollup merge of #140936 - teor2345:wtf-surrogate-docs, r=workingjubileeJacob Pratt-6/+6
Clarify WTF-8 safety docs This PR is a follow-up to PR #140159, which clarifies ~~two things~~: - the WTF-8 safety comment [was confusing](https://github.com/rust-lang/rust/pull/140159#discussion_r2082766965), either surrogate condition is actually sufficient for safety, both are not required - ~~the private `os_str::Slice` type name is easily confused with `std::slice`~~ ~~Happy to bikeshed the `OsSlice` name, other alternatives are `OsStrSlice` and `StrSlice`. Now it's got a distinct name from `std::slice`, it's easy to search and replace.~~ cc ``@thaliaarchi`` ``@workingjubilee``
2025-05-26Rollup merge of #134696 - ChrisDenton:normalize-lexically, r=workingjubileeJacob Pratt-0/+77
Implement `normalize_lexically` Implements #134694 This is, I think, the most straightforward implementation I could do, which will hopefully more easily allow experimentation if we decide to change the design here.
2025-05-25Implement normalize lexicallyChris Denton-0/+77
2025-05-25Rollup merge of #141108 - PaulDance:fix-extract_if-docs, r=Mark-SimulacrumJacob Pratt-10/+10
Docs(lib): Fix `extract_if` docs Various fixes to the documentation comments of the several `extract_if` collection methods available. It originally started with a small typo fix in `Vec`'s spotted when reading the 1.87 release notes, but then by looking at the others' for comparison in order to try determining what was the intended sentence, some inconsistencies were spotted. Therefore, some other changes are also proposed here to reduce these avoidable differences, going more and more nit-picky along the way. See the individual commits for more details about each change. `@rustbot` label T-libs A-collections A-docs
2025-05-25improve the `std::fs::create_dir_all` docs related to atomicityFluid-2/+2
2025-05-24make `OsString::new` and `PathBuf::new` unstably constcyrgani-5/+7