762 Commits

Author SHA1 Message Date
Jonathan Brouwer b7c319cfc4 Rollup merge of #150129 - a1phyr:improve_buf_api, r=joshtriplett
`BorrowedCursor`: make `init` a boolean

This PR changes uninitialized bytes tracking in `BorrowedBuf` from being byte-wise to being buffer-wise.

I've put all the API around `init` a new unstable feature `borrowed_buf_init`, to split the part that needs it and the part that doesn't. It will avoids accidental stabilization of this part.

I'm not really convinced of the rename of `advance_unchecked` to `advance`, but I did it anyway. The old `advance` was kept as `advance_checked`.

Alternative of rust-lang/rust#148937

Cc rust-lang/rust#78485 rust-lang/rust#117693
Cc @joshtriplett

r? @Amanieu
2026-04-05 00:18:45 +02:00
Jonathan Brouwer 46dcf270c2 Rollup merge of #154416 - vitkyrka:split-diag, r=Noratrieb
Add `IoSplit` diagnostic item for `std::io::Split`

Similar to the existing `IoLines` item.  It will be used in Clippy to detect uses of `Split` leading to infinite loops similar to the existing lint for `Lines`.
2026-03-29 21:39:29 +02:00
Ralf Jung d289cc4a38 Rollup merge of #154029 - xtqqczze:clear, r=joboet
Replace `truncate(0)` with `clear()`
2026-03-28 13:15:50 +01:00
Vincent Whitchurch eee01dd211 Add IoSplit diagnostic item for std::io::Split
Similar to the existing `IoLines` item.  It will be used in Clippy to
detect uses of `Split` leading to infinite loops similar to the existing
lint for `Lines`.
2026-03-26 09:40:58 +00:00
Ralf Jung 9dfdb6b4bc test copy_specializes_from_vecdeque: reduce iteration count for Miri 2026-03-20 15:55:56 +01:00
xtqqczze b9cd5923ae Replace truncate(0) with clear() 2026-03-19 13:55:02 +00:00
Benoît du Garreau d88f08e645 Rename BorrowedCursor::advance_unchecked to advance
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2026-03-10 18:03:22 +01:00
Benoît du Garreau df42b19088 core: Make BorrowedBuf::init a boolean
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2026-03-10 18:03:15 +01:00
Benoît du Garreau db392d4608 core: make BorrowedCursor::ensure_init return &[u8] 2026-03-10 18:03:15 +01:00
Lukas Bergdoll 58be5d6620 Move assert_matches to planned stable path 2026-01-21 23:17:24 +01:00
bors 844f13103a Auto merge of #151228 - cyrgani:less-feature, r=jhpratt
remove multiple unhelpful `reason = "..."` values from `#[unstable(...)]` invocations

The vast majority of `#[unstable()]` attributes already has no explicit reason specified. This PR removes the `reason = "..."` value for the following unhelpful or meaningless reasons: 
* "recently added"
* "new API"
* "recently redesigned"
* "unstable"

An example of how the message looks with and without a reason:

```rust
fn main() {
    Vec::<()>::into_parts;
    Vec::<()>::const_make_global;
}
```

```
error[E0658]: use of unstable library feature `box_vec_non_null`: new API
 --> src/main.rs:2:5
  |
2 |     Vec::<()>::into_parts;
  |     ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #130364 <https://github.com/rust-lang/rust/issues/130364> for more information
  = help: add `#![feature(box_vec_non_null)]` to the crate attributes to enable
  = note: this compiler was built on 2026-01-15; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `const_heap`
 --> src/main.rs:3:5
  |
3 |     Vec::<()>::const_make_global;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #79597 <https://github.com/rust-lang/rust/issues/79597> for more information
  = help: add `#![feature(const_heap)]` to the crate attributes to enable
  = note: this compiler was built on 2026-01-15; consider upgrading it if it is out of date
```

Most of the remaining reasons after this are something similar to "this is an implementation detail for XYZ" or "this is not public". If this PR is approved, I'll look into those next. 

The PR also removes the `fd_read` feature gate. It only consists of one attribute applied to an implementation inside a module that is already private and unstable and should not be needed.
2026-01-17 06:27:42 +00:00
cyrgani f13b1549ce remove reason = "recently added" from #[unstable(...)] 2026-01-16 13:32:24 +00:00
Jonathan Brouwer 95ea4c5699 Rollup merge of #150723 - move_pal_error, r=@tgross35
std: move `errno` and related functions into `sys::io`

Part of rust-lang/rust#117276.

Currently, `errno` and related functions like `decode_error_kind` are split across `sys::pal` and `sys::pal::os`. This PR moves all of them into a new module inside `sys::io`.
2026-01-14 11:05:38 +01:00
joboet e259373ce9 std: move errno and related functions into sys::io 2026-01-13 11:08:27 +01:00
Martin Nordholts 8e3d60447c Finish transition from semitransparent to semiopaque for rustc_macro_transparency 2026-01-08 19:14:45 +01:00
朝倉水希 29f9397ad4 docs: fix typo in std::io::buffered 2025-12-29 14:50:58 +08:00
Amanieu d'Antras 4b07875505 Revert #148937 (Remove initialized-bytes tracking from BorrowedBuf and BorrowedCursor)
This caused several performance regressions because of existing code
which uses `Read::read` and therefore requires full buffer
initialization. This is particularly a problem when the same buffer is
re-used for multiple read calls since this means it needs to be fully
re-initialized each time.

There is still some benefit to landing the API changes, but we will have
to add private APIs so that the existing infrastructure can
track and avoid redundant initialization.
2025-12-17 14:34:56 +00:00
Jonathan Brouwer ff84058781 Rollup merge of #150064 - Ayush1325:uefi-io-repr-comment, r=bjorn3
std: io: error: Add comment for UEFI unpacked repr use

The following commit adds the comment explaining the rational why UEFI uses unpacked representation on 64-bit platforms as opposed to bit-packed representation used in all other 64-bit platforms.

r? `@bjorn3`
2025-12-16 20:21:13 +01:00
Jonathan Brouwer 297cdc8137 Rollup merge of #149804 - xiaolinny:main, r=lcnr
chore: fix some minor issues in the comments

fix some minor issues in the comments
2025-12-16 20:21:08 +01:00
Ayush Singh 4efe2681f7 std: io: error: Add comment for UEFI unpacked repr use
The following commit adds the comment explaining the rational why UEFI
uses unpacked representation on 64-bit platforms as opposed to bit-packed
representation used in all other 64-bit platforms.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-12-16 22:27:42 +05:30
joboet 33409da171 std: update references to FromInner etc. 2025-12-15 14:00:37 +01:00
joboet aa73de400d std: move RawOsError to sys::io 2025-12-15 13:48:30 +01:00
joboet 860716faa3 std: reorganize pipe implementations 2025-12-12 21:25:00 +01:00
xiaolinny d1d1181789 chore: fix some minor issues in the comments
Signed-off-by: xiaolinny <xiaolincode@outlook.com>
2025-12-09 17:07:18 +08:00
Matthias Krüger 170fffd31d Rollup merge of #149521 - a1phyr:improve_io_error, r=joboet
Improve `io::Error::downcast`

Rewrite this function to help to compiler understand what is going on here.
2025-12-04 09:22:10 +01:00
Matthias Krüger 45b2a711b1 Rollup merge of #148937 - joshtriplett:borrowed-buf-no-init-tracking, r=Amanieu
Remove initialized-bytes tracking from `BorrowedBuf` and `BorrowedCursor`

As discussed extensively in libs-api, the initialized-bytes tracking primarily benefits calls to `read_buf` that end up initializing the buffer and calling `read`, at the expense of calls to `read_buf` that *don't* need to initialize the buffer. Essentially, this optimizes for the past at the expense of the future. If people observe performance issues using `read_buf` (or something that calls it) with a given `Read` impl, they can fix those performance issues by implementing `read_buf` for that `Read`.

Update the documentation to stop talking about initialized-but-unfilled bytes.

Remove all functions that just deal with those bytes and their tracking, and remove usage of those methods.

Remove `BorrowedCursor::advance` as there's no longer a safe case for advancing within initialized-but-unfilled bytes. Rename `BorrowedCursor::advance_unchecked` to `advance`.

Update tests.

r? ``@Amanieu``
2025-12-03 07:36:12 +01:00
Josh Triplett 382509988b Remove initialized-bytes tracking from BorrowedBuf and BorrowedCursor
As discussed extensively in libs-api, the initialized-bytes tracking
primarily benefits calls to `read_buf` that end up initializing the
buffer and calling `read`, at the expense of calls to `read_buf` that
*don't* need to initialize the buffer. Essentially, this optimizes for
the past at the expense of the future. If people observe performance
issues using `read_buf` (or something that calls it) with a given `Read`
impl, they can fix those performance issues by implementing `read_buf`
for that `Read`.

Update the documentation to stop talking about initialized-but-unfilled
bytes.

Remove all functions that just deal with those bytes and their tracking,
and remove usage of those methods.

Remove `BorrowedCursor::advance` as there's no longer a safe case for
advancing within initialized-but-unfilled bytes. Rename
`BorrowedCursor::advance_unchecked` to `advance`.

Update tests.
2025-12-02 01:32:27 -08:00
Benoît du Garreau 7de190a64b io::Error::downcast: avoid reallocation in case of failure 2025-12-01 19:40:50 +01:00
joboet d870149672 std: move kernel_copy to sys 2025-11-17 17:44:21 +01:00
Josh Triplett 199f308446 Guard against incorrect read_buf_exact implementations 2025-11-12 23:12:37 -08:00
Josh Triplett 65b5d765bc Implement Read::read_array
Tracking issue: https://github.com/rust-lang/rust/issues/148848
2025-11-11 16:18:50 -08:00
Sebastian Speitel 3a20a4d0a5 Fix typo 2025-09-28 00:51:57 +02:00
Joe Birr-Pixton 1ae720a52d Fix spelling of "adaptor"
These docs are in en_US, so "adapter" is the correct spelling
(and indeed used in the next line.)
2025-09-16 11:51:19 +01:00
joboet 207a01e88f std: make address resolution weirdness local to SGX 2025-09-08 16:58:43 +02:00
Marijn Schouten 845311a065 remove deprecated Error::description in impls 2025-08-26 06:36:53 +00:00
Jacob Pratt d54aaed392 Rollup merge of #145525 - typesanitizer:vg/doc, r=Mark-Simulacrum
stdlib: Replace typedef -> type alias in doc comment

'typedef' is jargon from C and C++.

Since the Rust reference uses the term [type alias](https://doc.rust-lang.org/reference/items/type-aliases.html),
this patch changes the doc comment in io/error.rs
to also use 'type alias'.
2025-08-21 01:12:19 -04:00
Jacob Pratt 5fa33047a2 Rollup merge of #145006 - ginnyTheCat:docs-skip-until, r=ibraheemdev
Clarify EOF handling for `BufRead::skip_until`

This aligns `BufRead::skip_until`'s description more with `BufRead::read_until` in terms of how it handles EOF and extends the doctest to include this behavior.
2025-08-20 00:45:54 -04:00
许杰友 Jieyou Xu (Joe) bb4af94006 Rollup merge of #145538 - lolbinarycat:std-bufreader-buffer-backshift-less, r=tgross35
bufreader::Buffer::backshift: don't move the uninit bytes

previous code was perfectly sound because of MaybeUninit, but it did waste cycles on copying memory that is known to be uninitialized.
2025-08-19 19:50:01 +08:00
binarycat ab19755630 bufreader::Buffer::backshift: don't move the uninit bytes
previous code was perfectly sound because of MaybeUninit,
but it did waste cycles on copying memory that is
known to be uninitialized.
2025-08-17 14:13:05 -05:00
Varun Gandhi be9cd3cc0a stdlib: Replace typedef -> type alias in doc comment 2025-08-17 17:44:06 +08:00
Josh Triplett 1ae4a0cc34 library: Migrate from cfg_if to cfg_select
Migrate the standard library from using the external `cfg_if` crate to
using the now-built-in `cfg_select` macro.

This does not yet eliminate the dependency from
`library/std/Cargo.toml`, because while the standard library itself no
longer uses `cfg_if`, it also incorporates the `backtrace` crate, which
does.

Migration assisted by the following vim command (after selecting the
full `cfg_if!` invocation):

```
'<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e
```

This is imperfect, but substantially accelerated the process. This
prompts for confirmation on the `} else {` since that can also appear
inside one of the arms. This also requires manual intervention to handle
any multi-line conditions.
2025-08-16 05:28:31 -07:00
ginnyTheCat a7e8fe7311 Clarify EOF handling for BufRead::skip_until 2025-08-06 16:52:43 +02:00
Benoît du Garreau 803b4d2622 core: Remove BorrowedCursor::init_ref method
This method was not really useful: at no point one would only need to
read the initialized part of the cursor without mutating it.
2025-07-09 18:11:26 +02:00
Josh Stone 9ce8930da6 Update version placeholders 2025-07-01 10:54:33 -07:00
Folkert de Vries 1dfc8406dc make tidy-alphabetical use a natural sort 2025-06-25 22:52:38 +02:00
Samuel Tardieu 6a9f223f00 Add diagnostic items for Clippy 2025-06-20 17:53:09 +02:00
León Orell Valerian Liehr 590f630ec6 Rollup merge of #142102 - kiseitai3:141714_stdin_read_to_string_docs, r=tgross35
docs: Small clarification on the usage of read_to_string and read_to_end trait methods

Small clarification on the usage of read_to_string and read_to_end trait methods. The goal is to make it clear that these trait methods will become locked up if attempting to read to the end of stdin (which is a bit non-sensical unless the other end closes the pipe).

Fixes: rust-lang/rust#141714
2025-06-10 16:54:49 +02:00
kiseitai3 7d7fedbab4 docs: Small clarification on the usage of read_to_string and read_to_end trait methods 2025-06-10 05:08:39 +00:00
Tobias Bucher 4b1e28b21f Clarify description of Seek::stream_len
It can only describe the inner workings of the default implementation,
other implementations might not be implemented using seeks at all.
2025-06-05 16:27:28 +02:00
Tobias Bucher fde8a8d518 Optimize Seek::stream_len impl for File
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-05 16:27:27 +02:00