Skip to content
/ rust Public
forked from rust-lang/rust

Commit cdde1d2

Browse files
authored
Rollup merge of rust-lang#158580 - valentynkit:enotsup-unsupported, r=workingjubilee
std: map ENOTSUP to ErrorKind::Unsupported `ENOTSUP` and `EOPNOTSUPP` both mean the operation isn't supported. They're the same value on some targets (Linux, FreeBSD), where the existing `EOPNOTSUPP => Unsupported` arm (rust-lang#139822) already covers both, and different on others (Apple, OpenBSD), where `ENOTSUP` decodes to `Uncategorized` instead. I don't see a reason to treat it differently, so this maps `ENOTSUP` to `Unsupported` as well. It uses a match guard rather than an or-pattern, since the two are equal on the targets where they alias and an or-pattern would be unreachable there. Same shape as the `EAGAIN`/`EWOULDBLOCK` arm just below: ```rust x if x == libc::EOPNOTSUPP || x == libc::ENOTSUP => Unsupported, ``` This was raised once before (rust-lang#125228) and closed, since both errnos were left out of the original `Unsupported` PR (rust-lang#78880). rust-lang#139822 has since added `EOPNOTSUPP`, so the same reasoning now covers `ENOTSUP`. I didn't add a test, since the decode arms aren't tested today. r? libs
2 parents 23a5aec + aa49d14 commit cdde1d2

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • library/std/src/sys/io/error

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ pub fn decode_error_kind(errno: i32) -> io::ErrorKind {
157157
libc::ENOENT => NotFound,
158158
libc::ENOMEM => OutOfMemory,
159159
libc::ENOSPC => StorageFull,
160-
libc::ENOSYS => Unsupported,
161160
libc::EMLINK => TooManyLinks,
162161
libc::ENAMETOOLONG => InvalidFilename,
163162
libc::ENETDOWN => NetworkDown,
@@ -175,11 +174,16 @@ pub fn decode_error_kind(errno: i32) -> io::ErrorKind {
175174
libc::EXDEV => CrossesDevices,
176175
libc::EINPROGRESS => InProgress,
177176
libc::EMFILE | libc::ENFILE => TooManyOpenFiles,
178-
libc::EOPNOTSUPP => Unsupported,
179177
libc::EIO => InputOutputError,
180178

181179
libc::EACCES | libc::EPERM => PermissionDenied,
182180

181+
libc::ENOSYS => Unsupported,
182+
// EOPNOTSUPP and ENOTSUP can have the same value on some systems,
183+
// but different values on others (e.g. Apple), so we can't use a
184+
// match clause
185+
x if x == libc::EOPNOTSUPP || x == libc::ENOTSUP => Unsupported,
186+
183187
// These two constants can have the same value on some systems,
184188
// but different values on others, so we can't use a match
185189
// clause

0 commit comments

Comments
 (0)