File tree 1 file changed +4
-7
lines changed
1 file changed +4
-7
lines changed Original file line number Diff line number Diff line change @@ -101,19 +101,16 @@ impl Error {
101
101
/// It is a bug to pass an out-of-range `errno`. `EINVAL` would
102
102
/// be returned in such a case.
103
103
pub fn from_errno ( errno : crate :: ffi:: c_int ) -> Error {
104
- if errno < -( bindings:: MAX_ERRNO as i32 ) || errno >= 0 {
104
+ if let Some ( error) = Self :: try_from_errno ( errno) {
105
+ error
106
+ } else {
105
107
// TODO: Make it a `WARN_ONCE` once available.
106
108
crate :: pr_warn!(
107
109
"attempted to create `Error` with out of range `errno`: {}" ,
108
110
errno
109
111
) ;
110
- return code:: EINVAL ;
112
+ code:: EINVAL
111
113
}
112
-
113
- // INVARIANT: The check above ensures the type invariant
114
- // will hold.
115
- // SAFETY: `errno` is checked above to be in a valid range.
116
- unsafe { Error :: from_errno_unchecked ( errno) }
117
114
}
118
115
119
116
/// Creates an [`Error`] from a kernel error code.
You can’t perform that action at this time.
0 commit comments