From d48f297cd7a97a13a937a5d97945844885e0c21c Mon Sep 17 00:00:00 2001 From: Andy Freeland Date: Tue, 22 Jun 2021 10:06:28 -0700 Subject: [PATCH] Add ErrorKind::DirNotEmpty This patch adds the ability to express `ENOTEMPTY` as an `io::Error`. --- library/std/src/io/error.rs | 5 +++++ library/std/src/sys/unix/mod.rs | 1 + library/std/src/sys/wasi/mod.rs | 1 + library/std/src/sys/windows/c.rs | 1 + library/std/src/sys/windows/mod.rs | 1 + src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed | 3 ++- src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs | 1 + src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr | 2 +- 8 files changed, 13 insertions(+), 2 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 56e6f08268ca3..65887fa74e207 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -191,6 +191,10 @@ pub enum ErrorKind { /// to allocate enough memory. #[stable(feature = "out_of_memory_error", since = "1.54.0")] OutOfMemory, + + /// The operation failed because a directory is not empty. + #[stable(feature = "dir_not_empty_error", since = "1.55.0")] + DirNotEmpty, } impl ErrorKind { @@ -216,6 +220,7 @@ impl ErrorKind { ErrorKind::UnexpectedEof => "unexpected end of file", ErrorKind::Unsupported => "unsupported", ErrorKind::OutOfMemory => "out of memory", + ErrorKind::DirNotEmpty => "directory not empty", } } } diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index ca9cc8ca7ba39..f514024191758 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -149,6 +149,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { libc::EEXIST => ErrorKind::AlreadyExists, libc::ENOSYS => ErrorKind::Unsupported, libc::ENOMEM => ErrorKind::OutOfMemory, + libc::ENOTEMPTY => ErrorKind::DirNotEmpty, // These two constants can have the same value on some systems, // but different values on others, so we can't use a match diff --git a/library/std/src/sys/wasi/mod.rs b/library/std/src/sys/wasi/mod.rs index 45a829c0cd212..bfb3f2810f05f 100644 --- a/library/std/src/sys/wasi/mod.rs +++ b/library/std/src/sys/wasi/mod.rs @@ -77,6 +77,7 @@ pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { wasi::ERRNO_AGAIN => WouldBlock, wasi::ERRNO_NOSYS => Unsupported, wasi::ERRNO_NOMEM => OutOfMemory, + wasi::ERRNO_ENOTEMPTY => DirNotEmpty, _ => Other, } } diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index 193c28c7673d7..eed33d8d3b61d 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -183,6 +183,7 @@ pub const ERROR_BROKEN_PIPE: DWORD = 109; pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120; pub const ERROR_SEM_TIMEOUT: DWORD = 121; pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122; +pub const ERROR_DIR_NOT_EMPTY: DWORD = 145; pub const ERROR_ALREADY_EXISTS: DWORD = 183; pub const ERROR_ENVVAR_NOT_FOUND: DWORD = 203; pub const ERROR_NO_DATA: DWORD = 232; diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index f23e874f24905..4b220293ec116 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -71,6 +71,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { c::ERROR_NO_DATA => return ErrorKind::BrokenPipe, c::ERROR_INVALID_PARAMETER => return ErrorKind::InvalidInput, c::ERROR_NOT_ENOUGH_MEMORY | c::ERROR_OUTOFMEMORY => return ErrorKind::OutOfMemory, + c::ERROR_DIR_NOT_EMPTY => return ErrorKind::DirNotEmpty, c::ERROR_SEM_TIMEOUT | c::WAIT_TIMEOUT | c::ERROR_DRIVER_CANCEL_TIMEOUT diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed index 5ad27bb14501f..5d1ccc998648c 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed @@ -77,7 +77,7 @@ fn main() { let error_kind = ErrorKind::NotFound; match error_kind { ErrorKind::NotFound => {}, - ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | ErrorKind::OutOfMemory | _ => {}, + ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | ErrorKind::OutOfMemory | ErrorKind::DirNotEmpty | _ => {}, } match error_kind { ErrorKind::NotFound => {}, @@ -100,6 +100,7 @@ fn main() { ErrorKind::UnexpectedEof => {}, ErrorKind::Unsupported => {}, ErrorKind::OutOfMemory => {}, + ErrorKind::DirNotEmpty => {}, _ => {}, } } diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs index adca0738bba5b..f52fd645ed06e 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs @@ -100,6 +100,7 @@ fn main() { ErrorKind::UnexpectedEof => {}, ErrorKind::Unsupported => {}, ErrorKind::OutOfMemory => {}, + ErrorKind::DirNotEmpty => {}, _ => {}, } } diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr index 73f6a4a80c960..c17b70ba9c3e9 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr @@ -32,7 +32,7 @@ error: wildcard matches known variants and will also match future added variants --> $DIR/wildcard_enum_match_arm.rs:80:9 | LL | _ => {}, - | ^ help: try this: `ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | ErrorKind::OutOfMemory | _` + | ^ help: try this: `ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | ErrorKind::OutOfMemory | ErrorKind::DirNotEmpty | _` error: aborting due to 5 previous errors