Skip to content

Commit 9170ff7

Browse files
Rollup merge of rust-lang#155574 - bushrat011899:core_io_raw_os_error, r=Mark-Simulacrum
Move `std::io::RawOsError` to `core::io` ACP: rust-lang/libs-team#755 Tracking issue: rust-lang#154046 Related: rust-lang#154654 ## Description As a part of moving components of `std::io` into `alloc::io` and `core::io`, there will need to be a new home for the type `RawOsError`. In this PR, I propose moving it to `core::io`, and removing it from `std::sys`. I suspect this will be quite controversial as it is a platform dependent type, but this is not the only instance of a type being conditioned on `target_os` in `core` (e.g., `core::os` and `core::ffi`). Since `RawOsError` is currently unstable, I think it's reasonable to make this move now, and worry about making it platform independent if/when it is stabilized (e.g., replacing it with a wrapper around `isize` on all platforms). --- ## Notes * No AI tooling of any kind was used during the creation of this PR.
2 parents eb779a1 + 7653e5e commit 9170ff7

7 files changed

Lines changed: 22 additions & 20 deletions

File tree

library/core/src/io/error.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
use crate::fmt;
44

5+
/// The type of raw OS error codes.
6+
///
7+
/// This is an [`i32`] on all currently supported platforms, but platforms
8+
/// added in the future (such as UEFI) may use a different primitive type like
9+
/// [`usize`]. Use `as` or [`into`] conversions where applicable to ensure maximum
10+
/// portability.
11+
///
12+
/// [`into`]: Into::into
13+
#[unstable(feature = "raw_os_error_ty", issue = "107792")]
14+
pub type RawOsError = cfg_select! {
15+
target_os = "uefi" => usize,
16+
_ => i32,
17+
};
18+
519
/// A list specifying general categories of I/O error.
620
///
721
/// This list is intended to grow over time and it is not recommended to

library/core/src/io/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ mod error;
77
pub use self::borrowed_buf::{BorrowedBuf, BorrowedCursor};
88
#[unstable(feature = "core_io", issue = "154046")]
99
pub use self::error::ErrorKind;
10+
#[unstable(feature = "raw_os_error_ty", issue = "107792")]
11+
pub use self::error::RawOsError;

library/std/src/io/error.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ mod tests;
33

44
#[stable(feature = "rust1", since = "1.0.0")]
55
pub use core::io::ErrorKind;
6+
#[unstable(feature = "raw_os_error_ty", issue = "107792")]
7+
pub use core::io::RawOsError;
68

79
// On 64-bit platforms, `io::Error` may use a bit-packed representation to
810
// reduce size. However, this representation assumes that error codes are
@@ -140,17 +142,6 @@ enum ErrorData<C> {
140142
Custom(C),
141143
}
142144

143-
/// The type of raw OS error codes returned by [`Error::raw_os_error`].
144-
///
145-
/// This is an [`i32`] on all currently supported platforms, but platforms
146-
/// added in the future (such as UEFI) may use a different primitive type like
147-
/// [`usize`]. Use `as`or [`into`] conversions where applicable to ensure maximum
148-
/// portability.
149-
///
150-
/// [`into`]: Into::into
151-
#[unstable(feature = "raw_os_error_ty", issue = "107792")]
152-
pub type RawOsError = sys::io::RawOsError;
153-
154145
// `#[repr(align(4))]` is probably redundant, it should have that value or
155146
// higher already. We include it just because repr_bitpacked.rs's encoding
156147
// requires an alignment >= 4 (note that `#[repr(align)]` will not reduce the

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@
364364
#![feature(ptr_as_uninit)]
365365
#![feature(ptr_mask)]
366366
#![feature(random)]
367+
#![feature(raw_os_error_ty)]
367368
#![feature(slice_internals)]
368369
#![feature(slice_ptr_get)]
369370
#![feature(slice_range)]

library/std/src/sys/io/error/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,3 @@ cfg_select! {
4848
pub use generic::*;
4949
}
5050
}
51-
52-
pub type RawOsError = cfg_select! {
53-
target_os = "uefi" => usize,
54-
_ => i32,
55-
};

library/std/src/sys/io/error/motor.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::io;
2-
use crate::sys::io::RawOsError;
32

4-
pub fn errno() -> RawOsError {
3+
pub fn errno() -> io::RawOsError {
54
// Not used in Motor OS because it is ambiguous: Motor OS
65
// is micro-kernel-based, and I/O happens via a shared-memory
76
// 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 {
5756
}
5857
}
5958

60-
pub fn error_string(errno: RawOsError) -> String {
59+
pub fn error_string(errno: io::RawOsError) -> String {
6160
let error: moto_rt::Error = match errno {
6261
x if x < 0 => moto_rt::Error::Unknown,
6362
x if x > u16::MAX.into() => moto_rt::Error::Unknown,

library/std/src/sys/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub use error::errno_location;
6262
target_os = "wasi",
6363
))]
6464
pub use error::set_errno;
65-
pub use error::{RawOsError, decode_error_kind, errno, error_string, is_interrupted};
65+
pub use error::{decode_error_kind, errno, error_string, is_interrupted};
6666
pub use io_slice::{IoSlice, IoSliceMut};
6767
pub use is_terminal::is_terminal;
6868
pub use kernel_copy::{CopyState, kernel_copy};

0 commit comments

Comments
 (0)