From 54df693dd7e6668b78f0636e269f7f928d4932d2 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 24 Aug 2021 16:51:58 +0100 Subject: [PATCH 1/3] io::Error: alphabeticise the match in as_str() There was no rationale for the previous ordering. Signed-off-by: Ian Jackson --- library/std/src/io/error.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 829ef3d98bbc9..3f8f34793af33 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -307,13 +307,13 @@ pub enum ErrorKind { impl ErrorKind { pub(crate) fn as_str(&self) -> &'static str { use ErrorKind::*; + // Strictly alphabetical, please. (Sadly rustfmt cannot do this yet.) match *self { AddrInUse => "address in use", AddrNotAvailable => "address not available", AlreadyExists => "entity already exists", ArgumentListTooLong => "argument list too long", BrokenPipe => "broken pipe", - ResourceBusy => "resource busy", ConnectionAborted => "connection aborted", ConnectionRefused => "connection refused", ConnectionReset => "connection reset", @@ -321,9 +321,10 @@ impl ErrorKind { Deadlock => "deadlock", DirectoryNotEmpty => "directory not empty", ExecutableFileBusy => "executable file busy", + FileTooLarge => "file too large", FilenameTooLong => "filename too long", + FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)", FilesystemQuotaExceeded => "filesystem quota exceeded", - FileTooLarge => "file too large", HostUnreachable => "host unreachable", Interrupted => "operation interrupted", InvalidData => "invalid data", @@ -332,16 +333,16 @@ impl ErrorKind { NetworkDown => "network down", NetworkUnreachable => "network unreachable", NotADirectory => "not a directory", - StorageFull => "no storage space", NotConnected => "not connected", NotFound => "entity not found", + NotSeekable => "seek on unseekable file", Other => "other error", OutOfMemory => "out of memory", PermissionDenied => "permission denied", ReadOnlyFilesystem => "read-only filesystem or storage medium", + ResourceBusy => "resource busy", StaleNetworkFileHandle => "stale network file handle", - FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)", - NotSeekable => "seek on unseekable file", + StorageFull => "no storage space", TimedOut => "timed out", TooManyLinks => "too many links", Uncategorized => "uncategorized error", From 4c0203eb4b3406cd2088c5d0092a0445294e2f6c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 24 Aug 2021 16:53:58 +0100 Subject: [PATCH 2/3] io::ErrorKind: rationalise ordering in main enum It is useful to keep some coherent structure to this ordering. In particular, Other and Uncategorized should be next to each other, at the end. Also it seems to make sense to treat UnexpectedEof and OutOfMemory specially, since they are not like the other errors (despite OutOfMemory also being generatable by some OS errors). So: * Move Other to the end, just before Uncategorized * Move Unsupported to between Interrupted and UnexpectedEof * Add some comments documenting where to add things Signed-off-by: Ian Jackson --- library/std/src/io/error.rs | 41 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 3f8f34793af33..6880106a94371 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -261,18 +261,14 @@ pub enum ErrorKind { #[stable(feature = "rust1", since = "1.0.0")] Interrupted, - /// A custom error that does not fall under any other I/O error kind. - /// - /// This can be used to construct your own [`Error`]s that do not match any - /// [`ErrorKind`]. - /// - /// This [`ErrorKind`] is not used by the standard library. + /// This operation is unsupported on this platform. /// - /// Errors from the standard library that do not fall under any of the I/O - /// error kinds cannot be `match`ed on, and will only match a wildcard (`_`) pattern. - /// New [`ErrorKind`]s might be added in the future for some of those. - #[stable(feature = "rust1", since = "1.0.0")] - Other, + /// This means that the operation can never succeed. + #[stable(feature = "unsupported_error", since = "1.53.0")] + Unsupported, + + // ErrorKinds which are primarily categorisations for OS error + // codes should be added above. /// An error returned when an operation could not be completed because an /// "end of file" was reached prematurely. @@ -283,17 +279,28 @@ pub enum ErrorKind { #[stable(feature = "read_exact", since = "1.6.0")] UnexpectedEof, - /// This operation is unsupported on this platform. - /// - /// This means that the operation can never succeed. - #[stable(feature = "unsupported_error", since = "1.53.0")] - Unsupported, - /// An operation could not be completed, because it failed /// to allocate enough memory. #[stable(feature = "out_of_memory_error", since = "1.54.0")] OutOfMemory, + // "Unusual" error kinds which do not correspond simply to (sets + // of) OS error codes, should be added just above this comment. + // `Other` and `Uncategorised` should remain at the end: + + /// A custom error that does not fall under any other I/O error kind. + /// + /// This can be used to construct your own [`Error`]s that do not match any + /// [`ErrorKind`]. + /// + /// This [`ErrorKind`] is not used by the standard library. + /// + /// Errors from the standard library that do not fall under any of the I/O + /// error kinds cannot be `match`ed on, and will only match a wildcard (`_`) pattern. + /// New [`ErrorKind`]s might be added in the future for some of those. + #[stable(feature = "rust1", since = "1.0.0")] + Other, + /// Any I/O error from the standard library that's not part of this list. /// /// Errors that are `Uncategorized` now may move to a different or a new From 7b5c0ecb3d902149fd6caa1d673ad5f7751320f3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 24 Aug 2021 17:44:16 +0100 Subject: [PATCH 3/3] Fix tidy Signed-off-by: Ian Jackson --- library/std/src/io/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 6880106a94371..51666c0a3c7f1 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -269,7 +269,7 @@ pub enum ErrorKind { // ErrorKinds which are primarily categorisations for OS error // codes should be added above. - + // /// An error returned when an operation could not be completed because an /// "end of file" was reached prematurely. /// @@ -287,7 +287,7 @@ pub enum ErrorKind { // "Unusual" error kinds which do not correspond simply to (sets // of) OS error codes, should be added just above this comment. // `Other` and `Uncategorised` should remain at the end: - + // /// A custom error that does not fall under any other I/O error kind. /// /// This can be used to construct your own [`Error`]s that do not match any