Skip to content

Move std::io::Error into core#155625

Open
bushrat011899 wants to merge 8 commits intorust-lang:mainfrom
bushrat011899:core_io_error
Open

Move std::io::Error into core#155625
bushrat011899 wants to merge 8 commits intorust-lang:mainfrom
bushrat011899:core_io_error

Conversation

@bushrat011899
Copy link
Copy Markdown
Contributor

@bushrat011899 bushrat011899 commented Apr 21, 2026

View all comments

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

Description

Moves std::io::Error into core, deferring Box-adjacent methods to incoherent implementations in alloc, and RawOsError methods to std. This requires some substantial changes to the internals of Error, but none of them are breaking changes or externally visible.

Notably, I've replaced usage of Box with a wrapper around a pointer and an appropriate drop function. This requires the addition of quite a few lines of unsafe, but is required to work around Box only being accessible from alloc. Additionally, an atomic pointer to a VTable is used for working with RawOsError in core, since we cannot know the required implementations without std.


Notes

The hyperlink to `std::io::Error` will not be valid when moved to `core::io`.
There is also a typo which I might as well fix while I'm here.
Inconsistently referenced through `std::sys` and `std::io`. Choosing `std::io` as the canonical source to make migration to `core::io` cleaner.
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 21, 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.

Comment thread library/core/src/io/error/os_functions_atomic.rs
@bushrat011899 bushrat011899 force-pushed the core_io_error branch 2 times, most recently from 93b1fa3 to d3835aa Compare April 22, 2026 03:06
Comment thread library/core/src/io/error.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@programmerjake
Copy link
Copy Markdown
Member

example of how to link from core's docs to std: https://doc.rust-lang.org/1.95.0/src/core/str/mod.rs.html#200

@rustbot rustbot added the O-unix Operating system: Unix-like label Apr 22, 2026
@bushrat011899
Copy link
Copy Markdown
Contributor Author

example of how to link from core's docs to std: https://doc.rust-lang.org/1.95.0/src/core/str/mod.rs.html#200

That's a clever trick I never knew about! Looks like it's also required for linking to incoherent implementations even within the file that creates them too.

@bushrat011899

This comment has been minimized.

@rustbot rustbot removed the O-unix Operating system: Unix-like label Apr 22, 2026
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the O-unix Operating system: Unix-like label Apr 22, 2026
@bushrat011899

This comment has been minimized.

@rustbot rustbot removed the O-unix Operating system: Unix-like label Apr 22, 2026
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the O-unix Operating system: Unix-like label Apr 22, 2026
@bushrat011899

This comment has been minimized.

@rustbot rustbot removed the O-unix Operating system: Unix-like label Apr 22, 2026
@programmerjake
Copy link
Copy Markdown
Member

label -O-unix
See

maybe just leave it until you get the PR to work, that way there's less comment spam.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the O-unix Operating system: Unix-like label Apr 22, 2026
@bushrat011899 bushrat011899 changed the title [WIP]: Move std::io::Error into core Move std::io::Error into core Apr 22, 2026
@bushrat011899 bushrat011899 marked this pull request as ready for review April 22, 2026 15:07
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 22, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 22, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 22, 2026

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: @scottmcm, libs
  • @scottmcm, libs expanded to 7 candidates
  • Random selection from Mark-Simulacrum, jhpratt, scottmcm

jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 24, 2026
…ref, r=jhpratt

Generalize IO Traits for `Arc<T>` where `&T: IoTrait`

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

## Description

After experimenting with rust-lang#155625, I noticed `Seek` and `SeekFrom` can almost be moved to `core::io`. Unfortunately, the implementation of `Seek` for `Arc<File>` is a blocker for such a move, since `Arc` is not a fundamental type. This PR attempts to resolve this potential blocker by replacing the implementation with a more general alternative. An internal trait `IoHandle` has been added which types can implement to opt-in to `Read`/`Write`/`Seek` implementations for `Arc<Self>` as long as `&Self` implements said trait. Note that `BufRead` is excluded as the signature for `fill_buf` would require returning from a temporary.

Since this "blanket" implementation only applies to a single type which already implements the same traits, I believe this should have no user-facing impact.

If this PR was merged, rust-lang#134190 could be replaced with a 2 line PR:
```rust
impl IoHandle for TcpStream {}
impl IoHandle for UnixStream {}
```
Likewise for any other types, a table of which can be found [here](rust-lang/libs-team#504 (comment)). This is out of scope for this PR to avoid the need for an ACP.

---

## Notes

* See [this comment](rust-lang#154046 (comment)) for further details.
* No AI tooling of any kind was used during the creation of this PR.
rust-timer added a commit that referenced this pull request Apr 24, 2026
Rollup merge of #155684 - bushrat011899:blanket_io_seek_for_ref, r=jhpratt

Generalize IO Traits for `Arc<T>` where `&T: IoTrait`

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

## Description

After experimenting with #155625, I noticed `Seek` and `SeekFrom` can almost be moved to `core::io`. Unfortunately, the implementation of `Seek` for `Arc<File>` is a blocker for such a move, since `Arc` is not a fundamental type. This PR attempts to resolve this potential blocker by replacing the implementation with a more general alternative. An internal trait `IoHandle` has been added which types can implement to opt-in to `Read`/`Write`/`Seek` implementations for `Arc<Self>` as long as `&Self` implements said trait. Note that `BufRead` is excluded as the signature for `fill_buf` would require returning from a temporary.

Since this "blanket" implementation only applies to a single type which already implements the same traits, I believe this should have no user-facing impact.

If this PR was merged, #134190 could be replaced with a 2 line PR:
```rust
impl IoHandle for TcpStream {}
impl IoHandle for UnixStream {}
```
Likewise for any other types, a table of which can be found [here](rust-lang/libs-team#504 (comment)). This is out of scope for this PR to avoid the need for an ACP.

---

## Notes

* See [this comment](#154046 (comment)) for further details.
* No AI tooling of any kind was used during the creation of this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-unix Operating system: Unix-like 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants