Skip to content

Commit 148255c

Browse files
committed
error: Replace another as with use of TryFrom.
1 parent 40e873d commit 148255c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/error.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,16 @@ impl Error {
7777
/// [1]: https://doc.rust-lang.org/std/io/struct.Error.html#method.raw_os_error
7878
#[inline]
7979
pub fn raw_os_error(self) -> Option<i32> {
80-
if self.0.get() < Self::INTERNAL_START {
81-
match () {
82-
#[cfg(target_os = "solid_asp3")]
80+
const _: () = assert!(i32::MAX.unsigned_abs() == Error::INTERNAL_START - 1);
81+
i32::try_from(self.0.get()).ok().map(|errno| {
82+
if cfg!(target_os = "solid_asp3") {
8383
// On SOLID, negate the error code again to obtain the original
8484
// error code.
85-
() => Some(-(self.0.get() as i32)),
86-
#[cfg(not(target_os = "solid_asp3"))]
87-
() => Some(self.0.get() as i32),
85+
-errno
86+
} else {
87+
errno
8888
}
89-
} else {
90-
None
91-
}
89+
})
9290
}
9391

9492
/// Extract the bare error code.

0 commit comments

Comments
 (0)