Skip to content

std: merge the unix-like io::error modules into one file#158870

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
valentynkit:posix-io-error-single-file
Jul 9, 2026
Merged

std: merge the unix-like io::error modules into one file#158870
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
valentynkit:posix-io-error-single-file

Conversation

@valentynkit

@valentynkit valentynkit commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

library/std/src/sys/io/error/ had a separate decode_error_kind (errno -> io::ErrorKind) for each POSIX-like target: unix.rs, wasi.rs, and teeos.rs. The three were near-identical hand copies and had drifted apart, each in its own way (#158490).

Per the discussion there, this folds wasi.rs and teeos.rs into unix.rs. decode_error_kind and is_interrupted are now shared; errno, set_errno, and error_string stay per-target behind cfg, next to the target-specific cases the file already had. A new mapping is written once and applies to all three.

The shared table is unix's existing one, so the merge also picks up the arms wasi and teeos were missing:

  • wasi now maps ENOTEMPTY -> DirectoryNotEmpty (was Uncategorized).
  • teeos now maps EINPROGRESS -> InProgress, EMFILE/ENFILE -> TooManyOpenFiles, and EOPNOTSUPP -> Unsupported (were Uncategorized).

All of those errnos are defined on the respective targets in libc, so the arms compile everywhere the file does. wasi's EWOULDBLOCK arm becomes the x == EAGAIN || x == EWOULDBLOCK guard the other two already use; that is a no-op on wasi, where EWOULDBLOCK == EAGAIN.

No test: with one shared decode_error_kind the copies can't drift again, and the decode arms are not tested today. (Let me know if it worth covering with tests)

Addresses #158490

r? @joboet

@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 Jul 6, 2026
@rustbot

rustbot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

joboet is currently at their maximum review capacity.
They may take a while to respond.

Comment thread library/std/src/sys/io/error/unix.rs Outdated

#[cfg(target_os = "teeos")]
pub fn errno() -> i32 {
unsafe { (*libc::__errno_location()) as i32 }

@joboet joboet Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it'd be good to use the extern "C" redefinition of __errno_location for TEEOS as well; that way it'll benefit from the #[ffi_const] annotation.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread library/std/src/sys/io/error/unix.rs Outdated
Comment on lines +227 to +238
#[cfg(target_os = "wasi")]
pub fn error_string(errno: i32) -> String {
let mut buf = [0 as libc::c_char; 1024];

let p = buf.as_mut_ptr();
unsafe {
if libc::strerror_r(errno as libc::c_int, p, buf.len()) < 0 {
panic!("strerror_r failure");
}
str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap().to_owned()
}
}

@joboet joboet Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd merge this with the UNIX implementation. Keeping the larger buffer size for WASI seems less risky to me, perhaps there's a good reason for it being larger? Not sure...

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Merged, kept the 1024 buffer for them.
I couldn't find the reason in the history either. But bigger is probably safer, will truncate longer messages.
The merge also switches wasi from unwrap to from_utf8_lossy.

@rustbot

rustbot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

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

@valentynkit valentynkit marked this pull request as ready for review July 6, 2026 18:03
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 6, 2026
@valentynkit

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@valentynkit valentynkit requested a review from joboet July 6, 2026 18:14
Comment thread library/std/src/sys/io/error/unix.rs Outdated
Comment on lines 6 to 8
#[cfg(any(target_family = "unix", target_os = "teeos"))]
unsafe extern "C" {
#[cfg(not(any(target_os = "dragonfly", target_os = "vxworks", target_os = "rtems")))]

@joboet joboet Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd just add WASI to these exceptions.

Suggested change
#[cfg(any(target_family = "unix", target_os = "teeos"))]
unsafe extern "C" {
#[cfg(not(any(target_os = "dragonfly", target_os = "vxworks", target_os = "rtems")))]
unsafe extern "C" {
#[cfg(not(any(target_os = "dragonfly", target_os = "vxworks", target_os = "rtems", target_os = "wasi")))]

View changes since the review

Comment thread library/std/src/sys/io/error/unix.rs Outdated
@@ -1,6 +1,9 @@
use crate::ffi::{CStr, c_char, c_int};
use crate::ffi::c_int;
#[cfg(any(target_family = "unix", target_os = "wasi"))]

@joboet joboet Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
#[cfg(any(target_family = "unix", target_os = "wasi"))]
#[cfg(not(target_os = "teeos"))]

View changes since the review

Comment thread library/std/src/sys/io/error/unix.rs Outdated
Comment on lines +44 to +47
#[cfg(all(
any(target_family = "unix", target_os = "teeos"),
not(any(target_os = "dragonfly", target_os = "vxworks", target_os = "rtems"))
))]

@joboet joboet Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread library/std/src/sys/io/error/unix.rs Outdated
#[cfg(any(target_family = "unix", target_os = "wasi"))]
pub fn error_string(errno: i32) -> String {
const TMPBUF_SZ: usize = 128;
const TMPBUF_SZ: usize = 1024;

@joboet joboet Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd keep the 128-byte buffer for UNIX – some smaller UNIXes are very mindful about stack usage. Try using cfg! perhaps.

View changes since the review

Comment thread library/std/src/sys/io/error/unix.rs Outdated
Comment on lines +61 to +66
#[cfg(all(
target_family = "unix",
not(target_os = "dragonfly"),
not(target_os = "vxworks"),
not(target_os = "rtems")
))]

@joboet joboet Jul 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's fine to leave this unused on TEEOS...

Suggested change
#[cfg(all(
target_family = "unix",
not(target_os = "dragonfly"),
not(target_os = "vxworks"),
not(target_os = "rtems")
))]
#[cfg(not(any(
target_os = "dragonfly",
target_os = "vxworks",
target_os = "rtems",
target_os = "wasi",
)))]

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for you guidance on this, applied your suggestions.
Sorry that haven't noticed it in first attempts.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No worries 😄!

@joboet joboet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks fine, thank you! Could you squash your commits, please?

View changes since this review

@valentynkit valentynkit force-pushed the posix-io-error-single-file branch from cf885f7 to 7b789b7 Compare July 7, 2026 17:43
@rustbot

This comment has been minimized.

The POSIX-like `decode_error_kind` copies under `sys/io/error/` (unix,
wasi, teeos) had drifted apart, each missing different arms. Fold wasi
and teeos into unix: `decode_error_kind` and `is_interrupted`
are shared, while `errno`, `set_errno`, `error_string`, and the
`errno_location` extern stay per-target behind `cfg`, expressed as
exceptions to the unix/wasi/teeos set rather than enumerating the
matching targets, matching the platform `cfg_attr`s the file already had.

teeos now goes through the shared `errno_location` extern instead of
calling `libc::__errno_location()` directly, so it gets the same
`#[ffi_const]` annotation as the other targets. `error_string` is shared
between unix and wasi, with the buffer sized per target: 128 bytes on
unix, where some targets are mindful of stack usage, and 1024 on wasi.

The shared decode table is unix's existing one, so wasi picks up
`ENOTEMPTY` -> `DirectoryNotEmpty` and teeos picks up `EINPROGRESS` ->
`InProgress`, `EMFILE`/`ENFILE` -> `TooManyOpenFiles`, and `EOPNOTSUPP`
-> `Unsupported`, all previously `Uncategorized` on those targets.

No test: with one shared `decode_error_kind` the copies can't drift
again, and no test asserts the errno to `ErrorKind` mappings today.
@valentynkit valentynkit force-pushed the posix-io-error-single-file branch from 7b789b7 to 865fb57 Compare July 7, 2026 17:45
@valentynkit

Copy link
Copy Markdown
Contributor Author

This looks fine, thank you! Could you squash your commits, please?

Sure, squashed it, the commit body is pretty detailed after squash, so if you would prefer to make it more concise, please let me know.

@joboet

joboet commented Jul 8, 2026

Copy link
Copy Markdown
Member

No, that's fine. Though I should point out that the merge commit will include the PR description anyway, so commit messages don't need to be that detailed...

@bors r+

@rust-bors

rust-bors Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 865fb57 has been approved by joboet

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 8, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 8, 2026
…file, r=joboet

std: merge the unix-like io::error modules into one file

`library/std/src/sys/io/error/` had a separate `decode_error_kind` (errno -> `io::ErrorKind`) for each POSIX-like target: `unix.rs`, `wasi.rs`, and `teeos.rs`. The three were near-identical hand copies and had drifted apart, each in its own way (rust-lang#158490).

Per the discussion there, this folds `wasi.rs` and `teeos.rs` into `unix.rs`. `decode_error_kind` and `is_interrupted` are now shared; `errno`, `set_errno`, and `error_string` stay per-target behind `cfg`, next to the target-specific cases the file already had. A new mapping is written once and applies to all three.

The shared table is unix's existing one, so the merge also picks up the arms wasi and teeos were missing:

- wasi now maps `ENOTEMPTY` -> `DirectoryNotEmpty` (was `Uncategorized`).
- teeos now maps `EINPROGRESS` -> `InProgress`, `EMFILE`/`ENFILE` -> `TooManyOpenFiles`, and `EOPNOTSUPP` -> `Unsupported` (were `Uncategorized`).

All of those errnos are defined on the respective targets in libc, so the arms compile everywhere the file does. wasi's `EWOULDBLOCK` arm becomes the `x == EAGAIN || x == EWOULDBLOCK` guard the other two already use; that is a no-op on wasi, where `EWOULDBLOCK == EAGAIN`.

No test: with one shared `decode_error_kind` the copies can't drift again, and the decode arms are not tested today. (Let me know if it worth covering with tests)

Addresses rust-lang#158490

r? @joboet
rust-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
Rollup of 25 pull requests

Successful merges:

 - #158871 (add relnotes for 1.97.0)
 - #158968 (stdarch subtree update)
 - #157690 (codegen_ssa: pack small const aggregates into immediate stores)
 - #158541 (Move `std::io::Write` to `core::io`)
 - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - #156370 (Reject linked dylib EII default overrides)
 - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s)
 - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158870 (std: merge the unix-like io::error modules into one file)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #158932 (Do not build the compiler when invoking `x perf compare`)
 - #158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #156144 (Better docs for PartialEq (includes macro rename))
 - #156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - #158307 (CI job for parallel frontend ui tests)
 - #158347 (Improve generic parameters handling for #[diagnostic::on_const])
 - #158722 (delegation: do not always inherit `ConstArgHasType` predicates)
 - #158741 (Simplify `Option::into_flat_iter` signature)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 9, 2026
…file, r=joboet

std: merge the unix-like io::error modules into one file

`library/std/src/sys/io/error/` had a separate `decode_error_kind` (errno -> `io::ErrorKind`) for each POSIX-like target: `unix.rs`, `wasi.rs`, and `teeos.rs`. The three were near-identical hand copies and had drifted apart, each in its own way (rust-lang#158490).

Per the discussion there, this folds `wasi.rs` and `teeos.rs` into `unix.rs`. `decode_error_kind` and `is_interrupted` are now shared; `errno`, `set_errno`, and `error_string` stay per-target behind `cfg`, next to the target-specific cases the file already had. A new mapping is written once and applies to all three.

The shared table is unix's existing one, so the merge also picks up the arms wasi and teeos were missing:

- wasi now maps `ENOTEMPTY` -> `DirectoryNotEmpty` (was `Uncategorized`).
- teeos now maps `EINPROGRESS` -> `InProgress`, `EMFILE`/`ENFILE` -> `TooManyOpenFiles`, and `EOPNOTSUPP` -> `Unsupported` (were `Uncategorized`).

All of those errnos are defined on the respective targets in libc, so the arms compile everywhere the file does. wasi's `EWOULDBLOCK` arm becomes the `x == EAGAIN || x == EWOULDBLOCK` guard the other two already use; that is a no-op on wasi, where `EWOULDBLOCK == EAGAIN`.

No test: with one shared `decode_error_kind` the copies can't drift again, and the decode arms are not tested today. (Let me know if it worth covering with tests)

Addresses rust-lang#158490

r? @joboet
rust-bors Bot pushed a commit that referenced this pull request Jul 9, 2026
Rollup of 23 pull requests

Successful merges:

 - #158968 (stdarch subtree update)
 - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158870 (std: merge the unix-like io::error modules into one file)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #158932 (Do not build the compiler when invoking `x perf compare`)
 - #158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #156144 (Better docs for PartialEq (includes macro rename))
 - #156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - #157995 (`Vec::dedup_by` docs explicit function argument order)
 - #158307 (CI job for parallel frontend ui tests)
 - #158741 (Simplify `Option::into_flat_iter` signature)
 - #158807 (Add regression test for CString::clone_into unwind safety)
 - #158862 (Fix the span for parameter suggestion )
 - #158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - #158902 (add codegen test for range length bound propagation)
 - #158913 (Update `browser-ui-test` version to `0.24.1`)
 - #158935 (std: support real fd methods on Emscripten)
 - #158978 (Add regression test for too-big by-value ABI args)
@rust-bors rust-bors Bot merged commit 376f430 into rust-lang:main Jul 9, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 9, 2026
rust-timer added a commit that referenced this pull request Jul 9, 2026
Rollup merge of #158870 - valentynkit:posix-io-error-single-file, r=joboet

std: merge the unix-like io::error modules into one file

`library/std/src/sys/io/error/` had a separate `decode_error_kind` (errno -> `io::ErrorKind`) for each POSIX-like target: `unix.rs`, `wasi.rs`, and `teeos.rs`. The three were near-identical hand copies and had drifted apart, each in its own way (#158490).

Per the discussion there, this folds `wasi.rs` and `teeos.rs` into `unix.rs`. `decode_error_kind` and `is_interrupted` are now shared; `errno`, `set_errno`, and `error_string` stay per-target behind `cfg`, next to the target-specific cases the file already had. A new mapping is written once and applies to all three.

The shared table is unix's existing one, so the merge also picks up the arms wasi and teeos were missing:

- wasi now maps `ENOTEMPTY` -> `DirectoryNotEmpty` (was `Uncategorized`).
- teeos now maps `EINPROGRESS` -> `InProgress`, `EMFILE`/`ENFILE` -> `TooManyOpenFiles`, and `EOPNOTSUPP` -> `Unsupported` (were `Uncategorized`).

All of those errnos are defined on the respective targets in libc, so the arms compile everywhere the file does. wasi's `EWOULDBLOCK` arm becomes the `x == EAGAIN || x == EWOULDBLOCK` guard the other two already use; that is a no-op on wasi, where `EWOULDBLOCK == EAGAIN`.

No test: with one shared `decode_error_kind` the copies can't drift again, and the decode arms are not tested today. (Let me know if it worth covering with tests)

Addresses #158490

r? @joboet
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jul 10, 2026
Rollup of 23 pull requests

Successful merges:

 - rust-lang/rust#158968 (stdarch subtree update)
 - rust-lang/rust#154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - rust-lang/rust#158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - rust-lang/rust#158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - rust-lang/rust#158870 (std: merge the unix-like io::error modules into one file)
 - rust-lang/rust#158920 (Update wasm-component-ld to 0.5.26)
 - rust-lang/rust#158926 (wrapping_sh* methods: clarify underspecified reference)
 - rust-lang/rust#158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - rust-lang/rust#158932 (Do not build the compiler when invoking `x perf compare`)
 - rust-lang/rust#158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - rust-lang/rust#151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - rust-lang/rust#156144 (Better docs for PartialEq (includes macro rename))
 - rust-lang/rust#156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - rust-lang/rust#157995 (`Vec::dedup_by` docs explicit function argument order)
 - rust-lang/rust#158307 (CI job for parallel frontend ui tests)
 - rust-lang/rust#158741 (Simplify `Option::into_flat_iter` signature)
 - rust-lang/rust#158807 (Add regression test for CString::clone_into unwind safety)
 - rust-lang/rust#158862 (Fix the span for parameter suggestion )
 - rust-lang/rust#158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - rust-lang/rust#158902 (add codegen test for range length bound propagation)
 - rust-lang/rust#158913 (Update `browser-ui-test` version to `0.24.1`)
 - rust-lang/rust#158935 (std: support real fd methods on Emscripten)
 - rust-lang/rust#158978 (Add regression test for too-big by-value ABI args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

3 participants