From e1ef601a730e172dfa5a390500fed499cd94ed9a Mon Sep 17 00:00:00 2001 From: Zac Harrold Date: Tue, 21 Apr 2026 09:03:22 +1000 Subject: [PATCH 1/3] Adjust Documentation for `RawOsError` 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. --- library/std/src/io/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 6f565bb37c53..35e2c8a29304 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -140,11 +140,11 @@ enum ErrorData { Custom(C), } -/// The type of raw OS error codes returned by [`Error::raw_os_error`]. +/// The type of raw OS error codes. /// /// This is an [`i32`] on all currently supported platforms, but platforms /// added in the future (such as UEFI) may use a different primitive type like -/// [`usize`]. Use `as`or [`into`] conversions where applicable to ensure maximum +/// [`usize`]. Use `as` or [`into`] conversions where applicable to ensure maximum /// portability. /// /// [`into`]: Into::into From 4cb72b3ca534f6119b40e6f7545e38f1dfde0f4a Mon Sep 17 00:00:00 2001 From: Zac Harrold Date: Tue, 21 Apr 2026 09:01:40 +1000 Subject: [PATCH 2/3] Adjust Usage of `RawOsError` Inconsistently referenced through `std::sys` and `std::io`. Choosing `std::io` as the canonical source to make migration to `core::io` cleaner. --- library/std/src/sys/io/error/motor.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/io/error/motor.rs b/library/std/src/sys/io/error/motor.rs index 7d612d817cdd..3c22d5fcb7b0 100644 --- a/library/std/src/sys/io/error/motor.rs +++ b/library/std/src/sys/io/error/motor.rs @@ -1,7 +1,6 @@ use crate::io; -use crate::sys::io::RawOsError; -pub fn errno() -> RawOsError { +pub fn errno() -> io::RawOsError { // Not used in Motor OS because it is ambiguous: Motor OS // is micro-kernel-based, and I/O happens via a shared-memory // ring buffer, so an I/O operation that on a unix is a syscall @@ -57,7 +56,7 @@ pub fn decode_error_kind(code: io::RawOsError) -> io::ErrorKind { } } -pub fn error_string(errno: RawOsError) -> String { +pub fn error_string(errno: io::RawOsError) -> String { let error: moto_rt::Error = match errno { x if x < 0 => moto_rt::Error::Unknown, x if x > u16::MAX.into() => moto_rt::Error::Unknown, From 7653e5ea01c18a8245df9dd48ea706c112f69b28 Mon Sep 17 00:00:00 2001 From: Zac Harrold Date: Tue, 21 Apr 2026 09:04:58 +1000 Subject: [PATCH 3/3] Move `RawOsError` to `core::io` --- library/core/src/io/error.rs | 14 ++++++++++++++ library/core/src/io/mod.rs | 2 ++ library/std/src/io/error.rs | 13 ++----------- library/std/src/lib.rs | 1 + library/std/src/sys/io/error/mod.rs | 5 ----- library/std/src/sys/io/mod.rs | 2 +- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/library/core/src/io/error.rs b/library/core/src/io/error.rs index fe12de2952f0..ff50b2822d05 100644 --- a/library/core/src/io/error.rs +++ b/library/core/src/io/error.rs @@ -2,6 +2,20 @@ use crate::fmt; +/// The type of raw OS error codes. +/// +/// This is an [`i32`] on all currently supported platforms, but platforms +/// added in the future (such as UEFI) may use a different primitive type like +/// [`usize`]. Use `as` or [`into`] conversions where applicable to ensure maximum +/// portability. +/// +/// [`into`]: Into::into +#[unstable(feature = "raw_os_error_ty", issue = "107792")] +pub type RawOsError = cfg_select! { + target_os = "uefi" => usize, + _ => i32, +}; + /// A list specifying general categories of I/O error. /// /// This list is intended to grow over time and it is not recommended to diff --git a/library/core/src/io/mod.rs b/library/core/src/io/mod.rs index c34421523b64..2d8273dd1b2d 100644 --- a/library/core/src/io/mod.rs +++ b/library/core/src/io/mod.rs @@ -7,3 +7,5 @@ pub use self::borrowed_buf::{BorrowedBuf, BorrowedCursor}; #[unstable(feature = "core_io", issue = "154046")] pub use self::error::ErrorKind; +#[unstable(feature = "raw_os_error_ty", issue = "107792")] +pub use self::error::RawOsError; diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 35e2c8a29304..360ca83c65a9 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -3,6 +3,8 @@ #[stable(feature = "rust1", since = "1.0.0")] pub use core::io::ErrorKind; +#[unstable(feature = "raw_os_error_ty", issue = "107792")] +pub use core::io::RawOsError; // On 64-bit platforms, `io::Error` may use a bit-packed representation to // reduce size. However, this representation assumes that error codes are @@ -140,17 +142,6 @@ enum ErrorData { Custom(C), } -/// The type of raw OS error codes. -/// -/// This is an [`i32`] on all currently supported platforms, but platforms -/// added in the future (such as UEFI) may use a different primitive type like -/// [`usize`]. Use `as` or [`into`] conversions where applicable to ensure maximum -/// portability. -/// -/// [`into`]: Into::into -#[unstable(feature = "raw_os_error_ty", issue = "107792")] -pub type RawOsError = sys::io::RawOsError; - // `#[repr(align(4))]` is probably redundant, it should have that value or // higher already. We include it just because repr_bitpacked.rs's encoding // requires an alignment >= 4 (note that `#[repr(align)]` will not reduce the diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 807befec1ad1..7287613bde46 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -363,6 +363,7 @@ #![feature(ptr_as_uninit)] #![feature(ptr_mask)] #![feature(random)] +#![feature(raw_os_error_ty)] #![feature(slice_internals)] #![feature(slice_ptr_get)] #![feature(slice_range)] diff --git a/library/std/src/sys/io/error/mod.rs b/library/std/src/sys/io/error/mod.rs index d7a0b9b4b301..4fca658a7dca 100644 --- a/library/std/src/sys/io/error/mod.rs +++ b/library/std/src/sys/io/error/mod.rs @@ -48,8 +48,3 @@ pub use generic::*; } } - -pub type RawOsError = cfg_select! { - target_os = "uefi" => usize, - _ => i32, -}; diff --git a/library/std/src/sys/io/mod.rs b/library/std/src/sys/io/mod.rs index b3587ab63696..445bcdef0aa1 100644 --- a/library/std/src/sys/io/mod.rs +++ b/library/std/src/sys/io/mod.rs @@ -62,7 +62,7 @@ mod is_terminal { target_os = "wasi", ))] pub use error::set_errno; -pub use error::{RawOsError, decode_error_kind, errno, error_string, is_interrupted}; +pub use error::{decode_error_kind, errno, error_string, is_interrupted}; pub use io_slice::{IoSlice, IoSliceMut}; pub use is_terminal::is_terminal; pub use kernel_copy::{CopyState, kernel_copy};