about summary refs log tree commit diff
path: root/library/std/src/io
AgeCommit message (Collapse)AuthorLines
2025-03-07Rollup merge of #138034 - thaliaarchi:use-prelude-size-of, r=tgross35Matthias Krüger-1/+0
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 #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-1/+0
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-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-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-02doc: clarify that consume can be called after BufReader::peekbinarycat-1/+5
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-28Use correct error message casing for `io::const_error`sNoratrieb-1/+1
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-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-23Auto merge of #137237 - cuviper:stage0, r=Mark-Simulacrumbors-2/+2
Master bootstrap update https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday r? `@Mark-Simulacrum`
2025-02-21Use faster thread_local! for stdoutKornel-1/+1
2025-02-21Clarify/update comments in `BufRead::read_line`'s default bodyFrank Steffahn-1/+1
with where to *actually* look for more details
2025-02-18update version placeholdersJosh Stone-2/+2
(cherry picked from commit e4840ce59bdddb19394df008c5c26d9c493725f8)
2025-02-18add last std diagnostic items for clippycyrgani-0/+1
2025-02-17Rollup merge of #136844 - thaliaarchi:const-io-error, r=ChrisDentonMatthias Krüger-1/+1
Use `const_error!` when possible Replace usages of `io::Error::new(io::ErrorKind::Variant, "constant string")` with `io::const_error!(io::ErrorKind::Variant, "constant string")` to avoid allocations when possible. Additionally, fix `&&str` error messages in SGX and missing/misplaced trailing commas in `const_error!`.
2025-02-14Forward all default methods for I/O implsThalia Archibald-0/+62
2025-02-13Use `slice::fill` in `io::Repeat` implementationDaniPopes-18/+10
Use the existing `fill` methods on slices instead of manually writing the fill loop.
2025-02-12Rollup merge of #136945 - samueltardieu:push-rsqlyknnvyqm, r=fmeaseJacob Pratt-0/+1
Add diagnostic item for `std::io::BufRead` This will be used in Clippy to detect unbuffered calls to `Read::bytes()`.
2025-02-12Add diagnostic item for `std::io::BufRead`Samuel Tardieu-0/+1
This will be used in Clippy to detect unbuffered calls to `Read::bytes()`.
2025-02-10Fix &&str and trailing commas in io::const_error!Thalia Archibald-1/+1
2025-02-10Implement `read*_exact` for `std:io::repeat`Benoît du Garreau-0/+11
cc #136756
2025-02-09Auto merge of #136751 - bjorn3:update_rustfmt, r=Mark-Simulacrumbors-3/+4
Update bootstrap compiler and rustfmt The rustfmt version we previously used formats things differently from what the latest nightly rustfmt does. This causes issues for subtrees that get formatted both in-tree and in their own repo. Updating the rustfmt used in-tree solves those issues. Also bumped the bootstrap compiler as the stage0 update command always updates both at the same time.
2025-02-08Rustfmtbjorn3-3/+4
2025-02-08Rollup merge of #135696 - joboet:move_pal_io, r=NoratriebMatthias Krüger-1/+1
std: move `io` module out of `pal`, get rid of `sys_common::io` Part of #117276. This does two related things: 1. It moves the platform-specific definitions for `IoSlice`, `IoSliceMut` and `is_terminal` out of `pal` and into `sys` and unifies some of them. 2. It gets rid of `sys_common::io`, moving the non-platform-specific test helpers into `std::test_helpers` and the buffer size definition to the new `sys::io` module.
2025-02-07std: get rid of `sys_common::io`joboet-1/+1
2025-02-06Stabilise 'Cursor::{get_mut, set_position}' in 'const' scenarios;Gabriel Bjørnager Jensen-2/+2
2025-01-28clarify BufRead::{fill_buf, consume} docsMarijn Schouten-24/+17
Fixes #85394
2025-01-26Test pipes also when not running on Windows and Linux simultaneouslyTobias Bucher-1/+1
Fixes https://github.com/rust-lang/rust/pull/135635#pullrequestreview-2574184488.
2025-01-26Update `std::io::{pipe, PipeReader, PipeWriter}` docs the new locationTobias Bucher-16/+20
Also create a section "Platform-specific behavior", don't hide required imports for code examples.
2025-01-26Move `std::io::pipe` code into its own fileTobias Bucher-272/+277
2025-01-25Rollup merge of #135948 - bjorn3:update_emscripten_std_tests, r=Mark-SimulacrumJacob Pratt-2/+1
Update emscripten std tests This disables a bunch of emscripten tests that test things emscripten doesn't support and re-enables a whole bunch of tests which now work just fine on emscripten. Tested with `EMCC_CFLAGS="-s MAXIMUM_MEMORY=2GB" ./x.py test library/ --target wasm32-unknown-emscripten`.
2025-01-25Improve and expand documentation of pipesJosh Triplett-8/+14
- Simplify some of the language - Minor grammar fixes - Don't imply that pipes *only* work across multiple processes; instead, *suggest* that they're typically used across two or more separate processes. - Specify that portable applications cannot use multiple readers or multiple writers for messages larger than a byte, due to potential interleaving. - Remove no-longer-referenced footnote URLs.
2025-01-24Remove a bunch of emscripten test ignoresbjorn3-2/+0
They are either outdated as emscripten now supports i128 or they are subsumed by #[cfg_attr(not(panic = "unwind"), ignore]
2025-01-24Fix testing of the standard library with Emscriptenbjorn3-0/+1
This does need EMCC_CFLAGS="-s MAXIMUM_MEMORY=2GB" avoid several OOMs.
2025-01-17Move `std::pipe::*` into `std::io`Jiahao XU-0/+266
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-01-11Add inherent versions of MaybeUninit methods for slicesltdk-1/+1
2025-01-10Use `NonNull::without_provenance` within the standard librarySamuel Tardieu-3/+4
This API removes the need for several `unsafe` blocks, and leads to clearer code.
2025-01-08update version placeholdersPietro Albini-2/+2
2024-12-21Avoid short writes in LineWriterChris Denton-6/+21
Also update the tests to avoid testing implementation details.
2024-12-21Less unwrap() in documentationKornel-10/+15
2024-12-06Rollup merge of #130254 - GrigorenkoPV:QuotaExceeded, r=dtolnayMatthias Krüger-9/+9
Stabilize `std::io::ErrorKind::QuotaExceeded` Also drop "Filesystem" from its name. See #130190 for more info. FCP in #130190 cc #86442 r? `@dtolnay`
2024-12-06Rollup merge of #130209 - GrigorenkoPV:CrossesDevices, r=dtolnayMatthias Krüger-1/+1
Stabilize `std::io::ErrorKind::CrossesDevices` FCP in #130191 cc #86442 See #130191 for more info and a recap of what has happened up until now. TLDR: This had been FCP'd in December 2022 with some other `ErrorKind`s, but the stabilization got postponed due to some concerns voiced about several of the variants. However, the only concern ever voiced for this variant in particular was a wish to rename this to `NotSameDevice` analogous to Windows's `ERROR_NOT_SAME_DEVICE` (as opposed to Unix's `EXDEV`). This suggestion did not receive any support. So let's try to FCP this as is. r? libs-api
2024-12-01add isatty alias for is_terminalcod10129-0/+1
2024-11-26std: update internal uses of `io::const_error!`joboet-21/+21
2024-11-25std: expose `const_io_error!` as `const_error!`joboet-20/+36
ACP: rust-lang/libs-team#205 Tracking issue: #133448
2024-11-20Rollup merge of #130800 - bjoernager:const-mut-cursor, r=joshtriplettMatthias Krüger-2/+4
Mark `get_mut` and `set_position` in `std::io::Cursor` as const. Relevant tracking issue: #130801 The methods `get_mut` and `set_position` can trivially be marked as const due to #57349 being stabilised.