@@ -88,12 +88,23 @@ impl From<alloc::ffi::NulError> for Error {
88
88
// doesn't accidentally get printed.
89
89
#[ cfg_attr( test, derive( Debug ) ) ]
90
90
enum ErrorData < C > {
91
- Os ( i32 ) ,
91
+ Os ( RawOsError ) ,
92
92
Simple ( ErrorKind ) ,
93
93
SimpleMessage ( & ' static SimpleMessage ) ,
94
94
Custom ( C ) ,
95
95
}
96
96
97
+ /// The type of raw OS error codes returned by [`Error::raw_os_error`].
98
+ ///
99
+ /// This is an [`i32`] on all currently supported platforms, but platforms
100
+ /// added in the future (such as UEFI) may use a different primitive type like
101
+ /// [`usize`]. Use `as`or [`into`] conversions where applicable to ensure maximum
102
+ /// portability.
103
+ ///
104
+ /// [`into`]: Into::into
105
+ #[ unstable( feature = "raw_os_error_ty" , issue = "none" ) ]
106
+ pub type RawOsError = i32 ;
107
+
97
108
// `#[repr(align(4))]` is probably redundant, it should have that value or
98
109
// higher already. We include it just because repr_bitpacked.rs's encoding
99
110
// requires an alignment >= 4 (note that `#[repr(align)]` will not reduce the
@@ -579,7 +590,7 @@ impl Error {
579
590
#[ must_use]
580
591
#[ inline]
581
592
pub fn last_os_error ( ) -> Error {
582
- Error :: from_raw_os_error ( sys:: os:: errno ( ) as i32 )
593
+ Error :: from_raw_os_error ( sys:: os:: errno ( ) )
583
594
}
584
595
585
596
/// Creates a new instance of an [`Error`] from a particular OS error code.
@@ -610,7 +621,7 @@ impl Error {
610
621
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
611
622
#[ must_use]
612
623
#[ inline]
613
- pub fn from_raw_os_error ( code : i32 ) -> Error {
624
+ pub fn from_raw_os_error ( code : RawOsError ) -> Error {
614
625
Error { repr : Repr :: new_os ( code) }
615
626
}
616
627
@@ -646,7 +657,7 @@ impl Error {
646
657
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
647
658
#[ must_use]
648
659
#[ inline]
649
- pub fn raw_os_error ( & self ) -> Option < i32 > {
660
+ pub fn raw_os_error ( & self ) -> Option < RawOsError > {
650
661
match self . repr . data ( ) {
651
662
ErrorData :: Os ( i) => Some ( i) ,
652
663
ErrorData :: Custom ( ..) => None ,
0 commit comments