Skip to content

Move OS-dependent parts of std::io to alloc#152918

Open
a1phyr wants to merge 4 commits intorust-lang:mainfrom
a1phyr:alloc_io
Open

Move OS-dependent parts of std::io to alloc#152918
a1phyr wants to merge 4 commits intorust-lang:mainfrom
a1phyr:alloc_io

Conversation

@a1phyr
Copy link
Copy Markdown
Contributor

@a1phyr a1phyr commented Feb 20, 2026

View all comments

ACP: rust-lang/libs-team#755
Tracking issue: #154046

This is the first (and the hardest) part of a plan to move most of std::io to alloc.

This PR has three commits:

  • The first enable alloc::ffi with no_rc and no_sync because they where annoying me.
  • The second moves io::Error to alloc.
    • Creating Error from raw OS errors is restricted to std via incoherent impls.
    • OS-dependent stuff needed by alloc is set at runtime by std when creating Error from raw OS errors (so no linking required, and not dependent of how Rust code is started). Can be moved to externally implementable one day.
  • The third moves IoSlice and IoSliceMut to alloc (required by Read and Write, exact layout depend on the OS).
    • Moves OS-dependent definition to alloc, but do not link to anything either.

I expect the introduction of OS-dependent code to alloc quite controversial, but please note that this PR does not expose anything OS-dependent to alloc users.

Also this PR abuses the fact that tidy does not warn on cfg_select! in alloc like it does for #[cfg()] 😈

The rest of std::io that can move should do so easily (obviously not things like stdio, IsTerminal, pipes, etc), except maybe for io::copy which has OS-dependent specialization. If this get merged, I will make a follup-up PR with all all this. In the meantime, a PR containing only the hard parts will avoid perpetual conflicts and rebases.

Some questions

Why not core?

Well this could be tried in the future. The main issue is that Read directly uses Vec.

Why not new Read/Write traits?

Why about not having them and make the existing one work for everyone?

Previous discussion (far larger than these few links)

Cc #48331
Prior try to move Error to core (not alloc): #116685
Prior discussion on this specific plan: https://internals.rust-lang.org/t/a-plan-to-move-most-of-std-io-to-alloc/23678/9
Many #![no_std] crates reimplementing std::io:

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 20, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 20, 2026

r? @jhpratt

rustbot has assigned @jhpratt.
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

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@lygstate
Copy link
Copy Markdown
Contributor

lygstate commented Feb 21, 2026

I have a idea, that move iovec into core::ffi first, and it's just different layout on UEFI/Windows/Other, for unknow or other triple, use

struct iovec {
    iov_base: *mut c_void,
    iov_len: usize,
}

for windows/UEFI, use

struct iovec {
    iov_len: c_ulong,
    iov_base: *mut c_void,
}

and for RawOsError, it's can also defined in core:ffi as

os_errno_t

@a1phyr
Copy link
Copy Markdown
Contributor Author

a1phyr commented Feb 21, 2026

It would possible indeed. I think that what we'll do will depend on T-libs team preference.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Feb 21, 2026
@rust-log-analyzer

This comment has been minimized.

@a1phyr
Copy link
Copy Markdown
Contributor Author

a1phyr commented Feb 21, 2026

To make rustdoc happy, I had to remove a bunch a links in io documentation. Most of them will be able to be added back when the rest of io arrives. The other will need a closer look to the incoherent impls weirdness.

@jhpratt
Copy link
Copy Markdown
Member

jhpratt commented Mar 1, 2026

@rustbot reroll

@rustbot rustbot assigned joboet and unassigned jhpratt Mar 1, 2026
@tgross35
Copy link
Copy Markdown
Contributor

tgross35 commented Mar 2, 2026

This is the first (and the hardest) part of a plan to move most of std::io to alloc.

A specific plan should be proposed as an ACP before starting too much work, there are tradeoffs and alternatives that need to be discussed and accepted by the libs-api team.

@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 2, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 2, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Mar 2, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 17, 2026
@rustbot

This comment has been minimized.

Comment thread library/alloc/src/io/error.rs
@a1phyr
Copy link
Copy Markdown
Contributor Author

a1phyr commented Mar 24, 2026

Can this get a perf run please?

@programmerjake
Copy link
Copy Markdown
Member

To make rustdoc happy, I had to remove a bunch a links in io documentation. Most of them will be able to be added back when the rest of io arrives. The other will need a closer look to the incoherent impls weirdness.

can you split out all the removal of links and stuff into a separate commit? that way it's easy to see what was removed and makes it much easier ro add them all back later since you can start by reverting just that commit.

@a1phyr
Copy link
Copy Markdown
Contributor Author

a1phyr commented Apr 1, 2026

Yes I can do that. I'm probably the one who will do the revert in the next PR anyway :)

@rustbot

This comment has been minimized.

Comment thread library/alloc/src/io/error/repr_unpacked.rs
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 19, 2026
…r=Mark-Simulacrum

Move `std::io::ErrorKind` to `core::io`

ACP: rust-lang/libs-team#755
Tracking issue: rust-lang#154046
Related: rust-lang#152918

## Description

I consider rust-lang#154046 to be really important for `no_std`, but I'm concerned rust-lang#152918 might be too controversial. As an alternative, I'd like to propose starting small with `ErrorKind`, since it can be moved somewhat trivially. It has no dependencies on functionality in `std`, no platform specific behaviour, and could provide an excellent bridging point for `no_std` IO libraries.

Since `std::io::Error` implements `From<ErrorKind>`, libraries could write functions which return `Result<T, core::io::ErrorKind>`, and therefore be usable in `std`-using libraries with the `?` operator. For that reason, I'd consider this to be a worthwhile change even if the rest of `std::io` couldn't be moved to `core`/`alloc`, and entirely compatible with any efforts to make such a change in the future.

## Notes

* This is my first PR against Rust, please let me know if there's anything I should be doing that I have not done. I tried reading through the library contributors guide but I'm sure I've missed _something_.
* No AI tooling of any kind was used in the creation of this PR.
* I believe it's appropriate that this be a part of the linked tracking issue, but please let me know if that's not the case!
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 20, 2026
…r=Mark-Simulacrum

Move `std::io::ErrorKind` to `core::io`

ACP: rust-lang/libs-team#755
Tracking issue: rust-lang#154046
Related: rust-lang#152918

## Description

I consider rust-lang#154046 to be really important for `no_std`, but I'm concerned rust-lang#152918 might be too controversial. As an alternative, I'd like to propose starting small with `ErrorKind`, since it can be moved somewhat trivially. It has no dependencies on functionality in `std`, no platform specific behaviour, and could provide an excellent bridging point for `no_std` IO libraries.

Since `std::io::Error` implements `From<ErrorKind>`, libraries could write functions which return `Result<T, core::io::ErrorKind>`, and therefore be usable in `std`-using libraries with the `?` operator. For that reason, I'd consider this to be a worthwhile change even if the rest of `std::io` couldn't be moved to `core`/`alloc`, and entirely compatible with any efforts to make such a change in the future.

## Notes

* This is my first PR against Rust, please let me know if there's anything I should be doing that I have not done. I tried reading through the library contributors guide but I'm sure I've missed _something_.
* No AI tooling of any kind was used in the creation of this PR.
* I believe it's appropriate that this be a part of the linked tracking issue, but please let me know if that's not the case!
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 20, 2026
…r=Mark-Simulacrum

Move `std::io::ErrorKind` to `core::io`

ACP: rust-lang/libs-team#755
Tracking issue: rust-lang#154046
Related: rust-lang#152918

## Description

I consider rust-lang#154046 to be really important for `no_std`, but I'm concerned rust-lang#152918 might be too controversial. As an alternative, I'd like to propose starting small with `ErrorKind`, since it can be moved somewhat trivially. It has no dependencies on functionality in `std`, no platform specific behaviour, and could provide an excellent bridging point for `no_std` IO libraries.

Since `std::io::Error` implements `From<ErrorKind>`, libraries could write functions which return `Result<T, core::io::ErrorKind>`, and therefore be usable in `std`-using libraries with the `?` operator. For that reason, I'd consider this to be a worthwhile change even if the rest of `std::io` couldn't be moved to `core`/`alloc`, and entirely compatible with any efforts to make such a change in the future.

## Notes

* This is my first PR against Rust, please let me know if there's anything I should be doing that I have not done. I tried reading through the library contributors guide but I'm sure I've missed _something_.
* No AI tooling of any kind was used in the creation of this PR.
* I believe it's appropriate that this be a part of the linked tracking issue, but please let me know if that's not the case!
rust-timer added a commit that referenced this pull request Apr 20, 2026
Rollup merge of #154654 - bushrat011899:core_io_error_kind, r=Mark-Simulacrum

Move `std::io::ErrorKind` to `core::io`

ACP: rust-lang/libs-team#755
Tracking issue: #154046
Related: #152918

## Description

I consider #154046 to be really important for `no_std`, but I'm concerned #152918 might be too controversial. As an alternative, I'd like to propose starting small with `ErrorKind`, since it can be moved somewhat trivially. It has no dependencies on functionality in `std`, no platform specific behaviour, and could provide an excellent bridging point for `no_std` IO libraries.

Since `std::io::Error` implements `From<ErrorKind>`, libraries could write functions which return `Result<T, core::io::ErrorKind>`, and therefore be usable in `std`-using libraries with the `?` operator. For that reason, I'd consider this to be a worthwhile change even if the rest of `std::io` couldn't be moved to `core`/`alloc`, and entirely compatible with any efforts to make such a change in the future.

## Notes

* This is my first PR against Rust, please let me know if there's anything I should be doing that I have not done. I tried reading through the library contributors guide but I'm sure I've missed _something_.
* No AI tooling of any kind was used in the creation of this PR.
* I believe it's appropriate that this be a part of the linked tracking issue, but please let me know if that's not the case!
@rust-bors

This comment has been minimized.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 21, 2026

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
Copy link
Copy Markdown
Contributor Author

a1phyr commented Apr 22, 2026

Can this get a perf run please?

Up on this!

Also friendly ping @jhpratt, when do you think that you will have time to review this?

@jhpratt
Copy link
Copy Markdown
Member

jhpratt commented Apr 22, 2026

I can take a look later, but note that I did reassign reviewers a bit ago :) For perf, I'll start a run if I don't see anything obvious.

@programmerjake
Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-acp This change is blocked on the author creating an ACP. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.