From acddbfde950d5ffe3b0764fd0723f1026b0d4731 Mon Sep 17 00:00:00 2001 From: Valentyn Kit Date: Fri, 10 Jul 2026 14:04:34 +0300 Subject: [PATCH] Add `io::ErrorKind::InputOutputError` `EIO` decoded to `ErrorKind::Uncategorized`, so a low-level I/O failure could only be detected through `raw_os_error()`. Map it, and the equivalent codes on Windows (`ERROR_IO_DEVICE`) and VEXos (`FR_DISK_ERR`), to a new unstable `InputOutputError` variant. --- library/core/src/io/error.rs | 10 ++++++++++ library/std/src/lib.rs | 1 + library/std/src/sys/fs/vexos.rs | 2 +- library/std/src/sys/io/error/unix.rs | 1 + library/std/src/sys/io/error/windows.rs | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/library/core/src/io/error.rs b/library/core/src/io/error.rs index eac7396bcfd83..61abdb16d07da 100644 --- a/library/core/src/io/error.rs +++ b/library/core/src/io/error.rs @@ -951,6 +951,14 @@ pub enum ErrorKind { #[unstable(feature = "io_error_too_many_open_files", issue = "158319")] TooManyOpenFiles, + /// A low-level input/output error. + /// + /// This usually indicates a hardware or device-level failure, such as a bad + /// disk sector or a removed device, but the operating system may also report + /// it for other low-level I/O conditions. + #[unstable(feature = "io_error_input_output_error", issue = "159066")] + InputOutputError, + // "Unusual" error kinds which do not correspond simply to (sets // of) OS error codes, should be added just above this comment. // `Other` and `Uncategorized` should remain at the end: @@ -1001,6 +1009,7 @@ impl ErrorKind { FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)", HostUnreachable => "host unreachable", InProgress => "in progress", + InputOutputError => "input/output error", Interrupted => "operation interrupted", InvalidData => "invalid data", InvalidFilename => "invalid filename", @@ -1093,6 +1102,7 @@ impl ErrorKind { OutOfMemory, InProgress, TooManyOpenFiles, + InputOutputError, Uncategorized, }) } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 7cf576ecd8803..9c5b487d1cbf0 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -356,6 +356,7 @@ #![feature(hint_must_use)] #![feature(int_from_ascii)] #![feature(io_error_inprogress)] +#![feature(io_error_input_output_error)] #![feature(io_error_more)] #![feature(io_error_too_many_open_files)] #![feature(io_error_uncategorized)] diff --git a/library/std/src/sys/fs/vexos.rs b/library/std/src/sys/fs/vexos.rs index d13b28d2abffa..595296bd85c8a 100644 --- a/library/std/src/sys/fs/vexos.rs +++ b/library/std/src/sys/fs/vexos.rs @@ -545,7 +545,7 @@ fn map_fresult(fresult: vex_sdk::FRESULT) -> io::Result<()> { match fresult { vex_sdk::FRESULT::FR_OK => Ok(()), vex_sdk::FRESULT::FR_DISK_ERR => Err(io::const_error!( - io::ErrorKind::Uncategorized, + io::ErrorKind::InputOutputError, "internal function reported an unrecoverable hard error", )), vex_sdk::FRESULT::FR_INT_ERR => Err(io::const_error!( diff --git a/library/std/src/sys/io/error/unix.rs b/library/std/src/sys/io/error/unix.rs index 2feeefa2530c8..c545558c3867e 100644 --- a/library/std/src/sys/io/error/unix.rs +++ b/library/std/src/sys/io/error/unix.rs @@ -177,6 +177,7 @@ pub fn decode_error_kind(errno: i32) -> io::ErrorKind { libc::EINPROGRESS => InProgress, libc::EMFILE | libc::ENFILE => TooManyOpenFiles, libc::EOPNOTSUPP => Unsupported, + libc::EIO => InputOutputError, libc::EACCES | libc::EPERM => PermissionDenied, diff --git a/library/std/src/sys/io/error/windows.rs b/library/std/src/sys/io/error/windows.rs index 9af11588fe322..3e6e281c61a75 100644 --- a/library/std/src/sys/io/error/windows.rs +++ b/library/std/src/sys/io/error/windows.rs @@ -64,6 +64,7 @@ pub fn decode_error_kind(errno: i32) -> io::ErrorKind { c::ERROR_TOO_MANY_OPEN_FILES => return TooManyOpenFiles, c::ERROR_FILENAME_EXCED_RANGE => return InvalidFilename, c::ERROR_CANT_RESOLVE_FILENAME => return FilesystemLoop, + c::ERROR_IO_DEVICE => return InputOutputError, _ => {} }