Skip to content

Migrate rest of std::io to alloc - #154684

Closed
a1phyr wants to merge 9 commits into
rust-lang:mainfrom
a1phyr:alloc_io_full
Closed

Migrate rest of std::io to alloc#154684
a1phyr wants to merge 9 commits into
rust-lang:mainfrom
a1phyr:alloc_io_full

Conversation

@a1phyr

@a1phyra1phyr commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Based on #152918

Tracking issue: #154046

Special things to note:

  • Allows warning in alloc doc tests
  • Implementation of IO traits for Arc. Unlike Generalize io for Arc #130675, this PR restricts the implementation more to avoid bad implementations such as Arc<[u8]>.
    Another way to do this would be to bypass orphan rule. Is it possible in std?

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Apr 1, 2026
@rustbot

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 7 candidates
  • Random selection from Mark-Simulacrum, jhpratt

@rustbot

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@a1phyr
a1phyr marked this pull request as draft April 1, 2026 15:42
@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 1, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-2 failed! Check out the build log: (web)(plain enhanced)(plain)

Click to see the possible cause of the failure (guessed by this bot)
Executing "/scripts/stage_2_test_set2.sh"
+ /scripts/stage_2_test_set2.sh
PR_CI_JOB set; skipping tidy
+ '[' 1 == 1 ']'
+ echo 'PR_CI_JOB set; skipping tidy'
+ SKIP_TIDY='--skip tidy'
+ ../x.py --stage 2 test --skip tidy --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest
##[group]Building bootstrap
Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
downloading https://static.rust-lang.org/dist/2026-03-05/rustfmt-nightly-aarch64-unknown-linux-gnu.tar.xz
---
io::buffered::panic_in_write_doesnt_flush_in_drop
test result: FAILED. 997 passed; 1 failed; 29 ignored; 0 measured; 0 filtered out; finished in 1.42s
error: test failed, to rerun pass `-p alloctests --test alloctests`
env -u RUSTC_WRAPPER CARGO_ENCODED_RUSTDOCFLAGS="-Csymbol-mangling-version=v0\u{1f}-Zannotate-moves\u{1f}-Zrandomize-layout\u{1f}-Zunstable-options\u{1f}--check-cfg=cfg(bootstrap)\u{1f}-Wrustdoc::invalid_codeblock_attributes\u{1f}--crate-version\u{1f}1.96.0-nightly\t(43bbeab9e\t2026-04-03)" CARGO_ENCODED_RUSTFLAGS="-Csymbol-mangling-version=v0\u{1f}-Zannotate-moves\u{1f}-Zrandomize-layout\u{1f}-Zunstable-options\u{1f}--check-cfg=cfg(bootstrap)\u{1f}-Zmacro-backtrace\u{1f}-Csplit-debuginfo=off\u{1f}-Clink-arg=-L/usr/lib/llvm-21/lib\u{1f}-Cllvm-args=-import-instr-limit=10\u{1f}-Clink-args=-Wl,-z,origin\u{1f}-Clink-args=-Wl,-rpath,$ORIGIN/../lib\u{1f}--cap-lints=allow\u{1f}--cfg\u{1f}randomized_layouts" RUSTC="/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/dist/rustc-clif" RUSTDOC="/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/dist/rustdoc-clif" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo" "test" "--manifest-path" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/sysroot_tests/Cargo.toml" "--target-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/sysroot_tests_target" "--locked" "--target" "aarch64-unknown-linux-gnu" "-p" "coretests" "-p" "alloctests" "--tests" "--" "-q" exited with status ExitStatus(unix_wait_status(25856))
Command `/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo run -Zwarnings --target aarch64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color=always --profile=release --manifest-path /checkout/compiler/rustc_codegen_cranelift/build_system/Cargo.toml -- test --download-dir /checkout/obj/build/cg_clif_download --out-dir /checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif --no-unstable-features --use-backend cranelift --sysroot llvm --skip-test testsuite.extended_sysroot [workdir=/checkout/compiler/rustc_codegen_cranelift]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/test.rs:3909:25
Executed at: src/bootstrap/src/core/build_steps/test.rs:3954:26
--- BACKTRACE vvv
0: std::backtrace_rs::backtrace::libunwind::trace
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
1: std::backtrace_rs::backtrace::trace_unsynchronized::<<std::backtrace::Backtrace>::create::{closure#0}>
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
2: <std::backtrace::Backtrace>::create
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/backtrace.rs:331:13
3: <bootstrap::utils::exec::DeferredCommand>::finish_process
at /checkout/src/bootstrap/src/utils/exec.rs:939:17
4: <bootstrap::utils::exec::DeferredCommand>::wait_for_output::<&bootstrap::utils::exec::ExecutionContext>
at /checkout/src/bootstrap/src/utils/exec.rs:831:21
5: <bootstrap::utils::exec::ExecutionContext>::run
at /checkout/src/bootstrap/src/utils/exec.rs:741:45
6: <bootstrap::utils::exec::BootstrapCommand>::run::<&bootstrap::core::builder::Builder>
at /checkout/src/bootstrap/src/utils/exec.rs:339:27
7: <bootstrap::core::build_steps::test::CodegenCranelift as bootstrap::core::builder::Step>::run
at /checkout/src/bootstrap/src/core/build_steps/test.rs:3954:26
8: <bootstrap::core::builder::Builder>::ensure::<bootstrap::core::build_steps::test::CodegenCranelift>
at /checkout/src/bootstrap/src/core/builder/mod.rs:1579:36
9: <bootstrap::core::build_steps::test::CodegenCranelift as bootstrap::core::builder::Step>::make_run
at /checkout/src/bootstrap/src/core/build_steps/test.rs:3895:17
10: <bootstrap::core::builder::StepDescription>::maybe_run
at /checkout/src/bootstrap/src/core/builder/mod.rs:476:13
11: bootstrap::core::builder::cli_paths::match_paths_to_steps_and_run
at /checkout/src/bootstrap/src/core/builder/cli_paths.rs:141:22
12: <bootstrap::core::builder::Builder>::run_step_descriptions
at /checkout/src/bootstrap/src/core/builder/mod.rs:1122:9
13: <bootstrap::core::builder::Builder>::execute_cli
at /checkout/src/bootstrap/src/core/builder/mod.rs:1101:14
14: <bootstrap::Build>::build
at /checkout/src/bootstrap/src/lib.rs:799:25
15: bootstrap::main
at /checkout/src/bootstrap/src/bin/main.rs:130:11
16: <fn() as core::ops::function::FnOnce<()>>::call_once
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/core/src/ops/function.rs:250:5
17: std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/sys/backtrace.rs:166:18
18: std::rt::lang_start::<()>::{closure#0}
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/rt.rs:206:18
19: <&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync as core::ops::function::FnOnce<()>>::call_once
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/core/src/ops/function.rs:287:21
20: std::panicking::catch_unwind::do_call::<&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync, i32>
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panicking.rs:581:40
21: std::panicking::catch_unwind::<i32, &dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync>
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panicking.rs:544:19
22: std::panic::catch_unwind::<&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync, i32>
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panic.rs:359:14
23: std::rt::lang_start_internal::{closure#0}
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/rt.rs:175:24
24: std::panicking::catch_unwind::do_call::<std::rt::lang_start_internal::{closure#0}, isize>
at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panicking.rs:581:40
---
31: __libc_start_main
32: _start
Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `--stage 2 test --skip tidy --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest`
Build completed unsuccessfully in 0:21:54
local time: Fri Apr 3 12:52:28 UTC 2026
network time: Fri, 03 Apr 2026 12:52:29 GMT
##[error]Process completed with exit code 1.

@rust-bors

rust-borsBot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #154832) made this pull request unmergeable. Please resolve the merge conflicts.

Comment on lines +294 to +359
#[stable(feature = "arc_io_traits", since = "CURRENT_RUSTC_VERSION")]
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
impl<R> Read for Arc<R>
where
R: Read,
for<'a> &'a R: Read,
{
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
(&**self).read(buf)
}
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
(&**self).read_vectored(bufs)
}
fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
(&**self).read_buf(cursor)
}
#[inline]
fn is_read_vectored(&self) -> bool {
(&**self).is_read_vectored()
}
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
(&**self).read_to_end(buf)
}
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
(&**self).read_to_string(buf)
}
}
#[stable(feature = "arc_io_traits", since = "CURRENT_RUSTC_VERSION")]
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
impl<W> Write for Arc<W>
where
W: Write,
for<'a> &'a W: Write,
{
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
(&**self).write(buf)
}
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
(&**self).write_vectored(bufs)
}
#[inline]
fn is_write_vectored(&self) -> bool {
(&**self).is_write_vectored()
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
(&**self).flush()
}
}
#[stable(feature = "arc_io_traits", since = "CURRENT_RUSTC_VERSION")]
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
impl<S> Seek for Arc<S>
where
S: Seek,
for<'a> &'a S: Seek,
{
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
(&**self).seek(pos)
}
fn stream_len(&mut self) -> io::Result<u64> {
(&**self).stream_len()
}
fn stream_position(&mut self) -> io::Result<u64> {
(&**self).stream_position()
}
}

@bushrat011899bushrat011899Apr 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These implementations have some potential issues. See #155684 for just this problem split out into its own PR.

View changes since the review

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 12, 2026
Move `std::io::Cursor` to `core::io`
ACP: rust-lang/libs-team#755
Tracking issue: rust-lang#154046
Subset of: rust-lang#154684
## Description
Moves `std::io::Cursor` to `core::io`, leaving the IO trait implementations behind. They will be moved along with the traits themselves. Certain documentation links had to be amended, and a private/unstable `into_parts_mut` method was added to allow the internals to remain private.
---
## Notes
* This can be reviewed independently of the other PRs tracked in rust-lang#154046.
* No AI tooling of any kind was used during the creation of this PR.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 12, 2026
Move `std::io::util` to `core::io`
ACP: rust-lang/libs-team#755
Tracking issue: rust-lang#154046
Subset of: rust-lang#154684
## Description
Moves utility types and functions from `std::io::util` and `std::io` to `core::io`, leaving any IO trait implementations behind. They will be moved along with the traits themselves. Certain documentation links had to be amended.
- `Chain`
- `Empty`
- `Repeat`
- `Sink`
- `Take`
- `empty`
- `repeat`
- `sink`
---
## Notes
* This can be reviewed independently of the other PRs tracked in rust-lang#154046.
* `Chain` and `Take` were previously in the main `mod.rs` file for `std::io`, but I've chosen to move them into the `util.rs` file in `core::io` instead. I think they make more sense in that file, but I'm happy to move them into `mod.rs` if that's a controversial decision.
* No AI tooling of any kind was used during the creation of this PR.
rust-timer added a commit that referenced this pull request May 12, 2026
Rollup merge of #156428 - bushrat011899:core_io_cursor, r=nia-e
Move `std::io::Cursor` to `core::io`
ACP: rust-lang/libs-team#755
Tracking issue: #154046
Subset of: #154684
## Description
Moves `std::io::Cursor` to `core::io`, leaving the IO trait implementations behind. They will be moved along with the traits themselves. Certain documentation links had to be amended, and a private/unstable `into_parts_mut` method was added to allow the internals to remain private.
---
## Notes
* This can be reviewed independently of the other PRs tracked in #154046.
* No AI tooling of any kind was used during the creation of this PR.
@a1phyr

Copy link
Copy Markdown
ContributorAuthor

This was superseded by @bushrat011899's excellent work.

@a1phyra1phyr closed this Aug 1, 2026
@rustbotrustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 1, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@a1phyr@rustbot@rust-log-analyzer@bushrat011899@Mark-Simulacrum