about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2025-03-09std: move stdio to `sys`joboet-150/+77
As per #117276, this moves the platform definitions of `Stdout` and friends into `sys`. This PR also unifies the UNIX and Hermit implementations and moves the `__rust_print_err` function needed by libunwind on SGX into the dedicated module for such helper functions.
2025-03-09Rollup merge of #138276 - bdbai:fix-uwp-ntopenfile, r=ChrisDentonMatthias Krüger-0/+11
Lazy load NtOpenFile for UWP Lazily load `NtOpenFile` to allow libraries targeting UWP to build and link. Fixes #138257 . r? `@ChrisDenton`
2025-03-09Lazy load NtOpenFile for UWPbdbai-0/+11
2025-03-08Move fs into sysThalia Archibald-46/+61
2025-03-08Rollup merge of #138189 - GuillaumeGomez:env-var, r=joshtriplettJacob Pratt-0/+3
Mention `env` and `option_env` macros in `std::env::var` docs Fixes https://github.com/rust-lang/rust/issues/138159. Just like there are mentions in `env!` and `option_env!` docs to `std::env::var`, it'd be nice to have a "mention back" as well.
2025-03-08Rollup merge of #137528 - ChrisDenton:rename-win, r=joboetJacob Pratt-124/+57
Windows: Fix error in `fs::rename` on Windows 1607 Fixes #137499 There's a bug in our Windows implementation of `fs::rename` that only manifests on a specific version of Windows. Both newer and older versions of Windows work. I took the safest route to fixing this by using the old `MoveFileExW` function to implement this and only falling back to the new behaviour if that fails. This is similar to what is done in `unlink` (just above this function). try-job: dist-x86_64-mingw try-job: dist-x86_64-msvc
2025-03-07Rollup merge of #137606 - davidtwco:next-edition, r=traviscross,ehussJacob Pratt-0/+15
add a "future" edition This idea has been discussed previously [on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Continuous.20edition-like.20changes.3F/near/432559262) (though what I've implemented isn't exactly the "next"/"future" editions proposed in that message, just the "future" edition). I've found myself prototyping changes that involve edition migrations and wanting to target an upcoming edition for those migrations, but none exists. This should be permanently unstable and not removed.
2025-03-07Mention `env` and `option_env` macros in `std::env::var` docsGuillaume Gomez-0/+3
2025-03-07Rollup merge of #134797 - spastorino:ergonomic-ref-counting-1, r=nikomatsakisMatthias Krüger-2/+7
Ergonomic ref counting This is an experimental first version of ergonomic ref counting. This first version implements most of the RFC but doesn't implement any of the optimizations. This was left for following iterations. RFC: https://github.com/rust-lang/rfcs/pull/3680 Tracking issue: https://github.com/rust-lang/rust/issues/132290 Project goal: https://github.com/rust-lang/rust-project-goals/issues/107 r? ```@nikomatsakis```
2025-03-07Return OutOfMemoryError and update docsChris Denton-3/+3
2025-03-07Windows: Use MoveFileEx by default in `fs:rename`Chris Denton-123/+56
2025-03-07Auto merge of #138155 - matthiaskrgr:rollup-xq5buio, r=matthiaskrgrbors-150/+121
Rollup of 6 pull requests Successful merges: - #137674 (Enable `f16` for LoongArch) - #138034 (library: Use `size_of` from the prelude instead of imported) - #138060 (Revert #138019 after further discussion about how hir-pretty printing should work) - #138073 (Break critical edges in inline asm before code generation) - #138107 (`librustdoc`: clippy fixes) - #138111 (Use `default_field_values` for `rustc_errors::Context`, `rustc_session::config::NextSolverConfig` and `rustc_session::config::ErrorOutputType`) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-07Rollup merge of #138034 - thaliaarchi:use-prelude-size-of, r=tgross35Matthias Krüger-150/+121
library: Use `size_of` from the prelude instead of imported Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80. try-job: test-various try-job: x86_64-gnu try-job: x86_64-msvc-1
2025-03-07Rollup merge of #137832 - wgwoods:fix-bufreader-peek, r=joboetMatthias Krüger-5/+5
Fix crash in BufReader::peek() `bufreader_peek` tracking issue: #128405 This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
2025-03-07Rollup merge of #137777 - thaliaarchi:os_string-push-str, r=joboetMatthias Krüger-2/+58
Specialize `OsString::push` and `OsString as From` for UTF-8 When concatenating two WTF-8 strings, surrogate pairs at the boundaries need to be joined. However, since UTF-8 strings cannot contain surrogate halves, this check can be skipped when one string is UTF-8. Specialize `OsString::push` to use a more efficient concatenation in this case. The WTF-8 version of `OsString` tracks whether it is known to be valid UTF-8 with its `is_known_utf8` field. Specialize `From<AsRef<OsStr>>` so this can be set for UTF-8 string types. Unfortunately, a specialization for `T: AsRef<str>` conflicts with `T: AsRef<OsStr>`, so stamp out string types with a macro. r? ``@ChrisDenton``
2025-03-07Rollup merge of #137107 - thaliaarchi:io-optional-methods/cursors, r=joboetMatthias Krüger-14/+146
Override default `Write` methods for cursor-like types Override the default `io::Write` methods for cursor-like types to provide more efficient versions. Writes to resizable containers already write everything, so implement `write_all` and `write_all_vectored` in terms of those. For fixed-sized containers, cut out unnecessary error checking and looping for those same methods. | `impl Write for T` | `vectored` | `all` | `all_vectored` | `fmt` | | ------------------------------- | ---------- | ----- | -------------- | ------- | | `&mut [u8]` | Y | Y | new | | | `Vec<u8>` | Y | Y | new | #137762 | | `VecDeque<u8>` | Y | Y | new | #137762 | | `std::io::Cursor<&mut [u8]>` | Y | new | new | | | `std::io::Cursor<&mut Vec<u8>>` | Y | new | new | #137762 | | `std::io::Cursor<Vec<u8>>` | Y | new | new | #137762 | | `std::io::Cursor<Box<[u8]>>` | Y | new | new | | | `std::io::Cursor<[u8; N]>` | Y | new | new | | | `core::io::BorrowedCursor<'_>` | new | new | new | | Tracked in https://github.com/rust-lang/rust/issues/136756. # Open questions Is it guaranteed by `Write::write_all` that the maximal write is performed when not everything can be written? Its documentation describes the behavior of the default implementation, which writes until a 0-length write is encountered, thus implying that a maximal write is expected. In contrast, `Read::read_exact` declares that the contents of the buffer are unspecified for short reads. If it were allowed, these cursor-like types could bail on the write altogether if it has insufficient capacity.
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-150/+121
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-03-06Add examples in stdlib demonstrating the use syntaxSantiago Pastorino-2/+7
2025-03-06Rollup merge of #137327 - arlosi:home-dir, r=Mark-SimulacrumMichael Goulet-5/+0
Undeprecate env::home_dir #132515 fixed the implementation of `env::home_dir`, but didn't remove the deprecation. Based on [this comment](https://github.com/rust-lang/rust/pull/132515#discussion_r1829715262), libs-api decided to undeprecate in the next release. Let's do that! cc #132650
2025-03-05Rollup merge of #137477 - Ayush1325:uefi-service-binding, r=Noratrieb许杰友 Jieyou Xu (Joe)-1/+60
uefi: Add Service Binding Protocol abstraction - Some UEFI protocols such as TCP4, TCP6, UDP4, UDP6, etc are managed by service binding protocol. - A new instance of such protocols is created and destroyed using the corresponding service binding protocol. - This PR adds abstractions to make using such protocols simpler using Rust Drop trait. - The reason to add these abstractions in a seperate PR from TCP4 Protocol is to make review easier. [EFI_SERVICE_BINDING_PROTCOL](https://uefi.org/specs/UEFI/2.11/11_Protocols_UEFI_Driver_Model.html#efi-service-binding-protocol) cc ````@nicholasbishop````
2025-03-05Rollup merge of #137463 - sunshowers:illumos-posix-spawn, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-1/+16
[illumos] attempt to use posix_spawn to spawn processes illumos has `posix_spawn`, and the very newest versions also have `_addchdir`, so use that. POSIX standardized this function so I also added a weak symbol lookup for the non `_np` version. (illumos has both.) This probably also works on Solaris, but I don't have access to an installation to validate this so I decided to focus on illumos instead. This is a nice ~4x performance improvement for process creation. My go-to as usual is nextest against the clap repo, which acts as a stress test for process creation -- with [this commit]: ```console $ cargo nextest run -E 'not test(ui_tests) and not test(example_tests)' before: Summary [ 1.747s] 879 tests run: 879 passed, 2 skipped after: Summary [ 0.445s] 879 tests run: 879 passed, 2 skipped ``` [this commit]: https://github.com/clap-rs/clap/commit/fde45f9aea766fb8de46e3d46e6575f393c3b6b9
2025-03-05Rollup merge of #137240 - jieyouxu:remove_dir_all, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-3/+5
Slightly reformat `std::fs::remove_dir_all` error docs To make the error cases easier to spot on a quick glance, as I've been bitten by this a couple of times already 💀 cc #137230.
2025-03-05Rollup merge of #136798 - pcorwin:master, r=tgross35许杰友 Jieyou Xu (Joe)-0/+34
Added documentation for flushing per #74348 Resolves #74348
2025-03-04Added documentation for flushingpcorwin-0/+34
2025-03-04Fix some typosfuyangpengqi-1/+1
Signed-off-by: fuyangpengqi <995764973@qq.com>
2025-03-02Rollup merge of #137375 - steffahn:clarify-read_line-comment, r=Mark-SimulacrumMatthias Krüger-1/+1
Minor internal comments fix for `BufRead::read_line` Just a little fix that came up while I was reading through this source code, and had to search for a few minutes to find out what was actually *meant* here.
2025-03-02uefi: Add Service Binding Protocol abstractionAyush Singh-1/+60
- Some UEFI protocols such as TCP4, TCP6, UDP4, UDP6, etc are managed by service binding protocol. - A new instance of such protocols is created and destroyed using the corresponding service binding protocol. - This PR adds abstractions to make using such protocols simpler using Rust Drop trait. - The reason to add these abstractions in a seperate PR from TCP4 Protocol is to make review easier. [EFI_SERVICE_BINDING_PROTCOL](https://uefi.org/specs/UEFI/2.11/11_Protocols_UEFI_Driver_Model.html#efi-service-binding-protocol) Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-01Rollup merge of #137809 - Noratrieb:io-error-casing, r=thomccMatthias Krüger-72/+72
Use correct error message casing for `io::const_error`s Error messages are supposed to start with lowercase letters, but a lot of `io::const_error` messages did not. This fixes them to start with a lowercase letter. I did consider adding a const check for this to the macro, but some of them start with proper nouns that make sense to uppercase them. See https://doc.rust-lang.org/1.85.0/std/error/trait.Error.html
2025-02-28Fix logic error in Buffer::read_more()Will Woods-2/+2
Buffer::read_more() is supposed to refill the buffer without discarding its contents, which are in the range `pos .. filled`. It mistakenly borrows the range `pos ..`, fills that, and then increments `filled` by the amount read. This overwrites the buffer's existing contents and sets `filled` to a too-large value that either exposes uninitialized bytes or walks off the end of the buffer entirely. This patch makes it correctly fill only the unfilled portion of the buffer, which should maintain all the type invariants and fix the test failure introduced in commit b1196717fcb.
2025-02-28Tweak BufReader::peek() doctest to expose bug in Buffer::read_more()Will Woods-3/+3
This patch makes BufReader::peek()'s doctest call read_more() to refill the buffer before the inner reader hits EOF. This exposes a bug in read_more() that causes an out-of-bounds slice access and segfault.
2025-02-28Specialize constructing OsString from stringsThalia Archibald-1/+24
The WTF-8 version of `OsString` tracks whether it is known to be valid UTF-8 with its `is_known_utf8` field. Specialize `From<AsRef<OsStr>>` so this can be set for UTF-8 string types.
2025-02-28Specialize OsString::push for stringsThalia Archibald-1/+34
When concatenating two WTF-8 strings, surrogate pairs at the boundaries need to be joined. However, since UTF-8 strings cannot contain surrogate halves, this check can be skipped when one string is UTF-8. Specialize `OsString::push` to use a more efficient concatenation in this case. Unfortunately, a specialization for `T: AsRef<str>` conflicts with `T: AsRef<OsStr>`, so stamp out string types with a macro.
2025-02-28Use correct error message casing for `io::const_error`sNoratrieb-72/+72
Error messages are supposed to start with lowercase letters, but a lot of `io::const_error` messages did not. This fixes them to start with a lowercase letter. I did consider adding a const check for this to the macro, but some of them start with proper nouns that make sense to uppercase them. See https://doc.rust-lang.org/1.85.0/std/error/trait.Error.html
2025-02-28Rollup merge of #137673 - ChrisDenton:search-path-bug, r=dtolnay许杰友 Jieyou Xu (Joe)-1/+2
Fix Windows `Command` search path bug Currently `Command::new` on Windows works differently depending on whether any environment variable is set. For example, ```rust // Searches for "myapp" in the application and system paths first (aka Windows native behaviour). Command::new("myapp").spawn(); // Search for "myapp" in `PATH` first Command::new("myapp").env("a", "b").spawn(); ``` This is a bug because the search path should only change if `PATH` is changed for the child (i.e. `.env("PATH", "...")`). This was discussed in a libs-api meeting where the exact semantics of `Command::new` was not decided but there seemed to be broad agreement that this particular thing is just a bug that can be fixed. r? libs-api
2025-02-27Override default Write methods for cursor-like typesThalia Archibald-14/+143
2025-02-27Inline VecDeque<u8> and BorrowedCursor methodsThalia Archibald-0/+3
All other methods in this file have #[inline] and these methods are very similar to those of &[u8] which are already inlined here.
2025-02-27Rollup merge of #137480 - fuzzypixelz:fix/124466, r=workingjubileeMatthias Krüger-1/+10
Return unexpected termination error instead of panicing in `Thread::join` There is a time window during which the OS can terminate a thread before stdlib can retreive its `Packet`. Currently the `Thread::join` panics with no message in such an event, which makes debugging difficult; fixes #124466.
2025-02-26Rollup merge of #137620 - SergioGasquez:fix/espidf-maybeunit, r=ChrisDentonLeón Orell Valerian Liehr-1/+1
Fix `attr` cast for espidf https://github.com/rust-lang/rust/pull/136826 broke ESP-IDF builds with: https://github.com/esp-rs/esp-idf-template/actions/runs/13516221587/job/37765336588. This PR fixes it. cc: ``@ivmarkov`` ``@xizheyin``
2025-02-26Fix Windows `Command` search path bugChris Denton-1/+2
2025-02-26Rollup merge of #137154 - thaliaarchi:wtf8-fast-paths, r=ChrisDentonLeón Orell Valerian Liehr-3/+27
Add UTF-8 validation fast paths in `Wtf8Buf` This adds two more fast paths for UTF-8 validation in `Wtf8Buf`, making use of the `is_known_utf8` flag added in https://github.com/rust-lang/rust/pull/96869 (Optimize `Wtf8Buf::into_string` for the case where it contains UTF-8). r? `@ChrisDenton`
2025-02-25fix: attr cast for espidfSergio Gasquez-1/+1
2025-02-25Use `.expect(..)` insteadMahmoud Mazouz-5/+10
2025-02-25Auto merge of #137571 - tgross35:rollup-i1tcnv1, r=tgross35bors-17/+19
Rollup of 8 pull requests Successful merges: - #134655 (Stabilize `hash_extract_if`) - #135933 (Explain how Vec::with_capacity is faithful) - #136668 (Stabilize `core::str::from_utf8_mut` as `const`) - #136775 (Update `String::from_raw_parts` safety requirements) - #137109 (stabilize extract_if) - #137349 (Implement `read_buf` for zkVM stdin) - #137493 (configure.py: don't instruct user to run nonexistent program) - #137516 (remove some unnecessary rustc_const_unstable) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-24Rollup merge of #137543 - petrochenkov:wintest, r=ChrisDentonMichael Goulet-0/+4
std: Fix another new symlink test on Windows Checking for `got_symlink_permission` first is a standard procedure for such tests.
2025-02-24Rollup merge of #137321 - aviraxp:patch-1, r=cuviperMichael Goulet-1/+3
Correct doc about `temp_dir()` behavior on Android Since commit https://github.com/aosp-mirror/platform_frameworks_base/commit/d5ccb038f69193fb63b5169d7adc5da19859c9d8, `TMPDIR` will be set to application's cache dir when app starts.
2025-02-24Rollup merge of #137349 - thaliaarchi:io-optional-methods/zkvm, r=NoratriebTrevor Gross-1/+9
Implement `read_buf` for zkVM stdin For the zkVM, even when a guest buffer is uninitialized, from the host's perspective it is just a normal piece of memory which was initialized before letting the guest write into it. This makes `sys_read` safe to use with an uninitialized buffer. See https://github.com/risc0/risc0/issues/2853. cc `@bobbobbio,` `@flaub` r? `@Noratrieb` Tracked in https://github.com/rust-lang/rust/issues/136756
2025-02-24Rollup merge of #134655 - GrigorenkoPV:hash_extract_if, r=cuviperTrevor Gross-16/+10
Stabilize `hash_extract_if` FCP complete: https://github.com/rust-lang/rust/issues/59618#issuecomment-2674880530 Tracking issue: #59618 Closes #59618
2025-02-24span: add a "future" editionDavid Wood-0/+15
It's hard to implement edition migrations without having a perma-unstable "future" edition to target.
2025-02-24std: Fix another new symlink test on WindowsVadim Petrochenkov-0/+4
2025-02-24Remove speculation on cause of errorMahmoud Mazouz-1/+1
Co-authored-by: Jubilee <workingjubilee@gmail.com>