Skip to content

Commit 82ecb0f

Browse files
Rollup merge of #88298 - ijackson:errorkind-reorder, r=dtolnay
Errorkind reorder I was doing a bit more work in this area and the untidiness of these two orderings bothered me. The commit messages have the detailed rationale. For your convenience, I c&p them here: ``` 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 ``` ``` io::Error: alphabeticise the match in as_str() There was no rationale for the previous ordering. ``` r? kennytm since that's who rust-highfive picked before, in #88294 which I accidentally closed.
2 parents 0aabf4b + 7b5c0ec commit 82ecb0f

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

library/std/src/io/error.rs

+30-22
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,15 @@ pub enum ErrorKind {
261261
#[stable(feature = "rust1", since = "1.0.0")]
262262
Interrupted,
263263

264-
/// A custom error that does not fall under any other I/O error kind.
265-
///
266-
/// This can be used to construct your own [`Error`]s that do not match any
267-
/// [`ErrorKind`].
268-
///
269-
/// This [`ErrorKind`] is not used by the standard library.
264+
/// This operation is unsupported on this platform.
270265
///
271-
/// Errors from the standard library that do not fall under any of the I/O
272-
/// error kinds cannot be `match`ed on, and will only match a wildcard (`_`) pattern.
273-
/// New [`ErrorKind`]s might be added in the future for some of those.
274-
#[stable(feature = "rust1", since = "1.0.0")]
275-
Other,
266+
/// This means that the operation can never succeed.
267+
#[stable(feature = "unsupported_error", since = "1.53.0")]
268+
Unsupported,
276269

270+
// ErrorKinds which are primarily categorisations for OS error
271+
// codes should be added above.
272+
//
277273
/// An error returned when an operation could not be completed because an
278274
/// "end of file" was reached prematurely.
279275
///
@@ -283,17 +279,28 @@ pub enum ErrorKind {
283279
#[stable(feature = "read_exact", since = "1.6.0")]
284280
UnexpectedEof,
285281

286-
/// This operation is unsupported on this platform.
287-
///
288-
/// This means that the operation can never succeed.
289-
#[stable(feature = "unsupported_error", since = "1.53.0")]
290-
Unsupported,
291-
292282
/// An operation could not be completed, because it failed
293283
/// to allocate enough memory.
294284
#[stable(feature = "out_of_memory_error", since = "1.54.0")]
295285
OutOfMemory,
296286

287+
// "Unusual" error kinds which do not correspond simply to (sets
288+
// of) OS error codes, should be added just above this comment.
289+
// `Other` and `Uncategorised` should remain at the end:
290+
//
291+
/// A custom error that does not fall under any other I/O error kind.
292+
///
293+
/// This can be used to construct your own [`Error`]s that do not match any
294+
/// [`ErrorKind`].
295+
///
296+
/// This [`ErrorKind`] is not used by the standard library.
297+
///
298+
/// Errors from the standard library that do not fall under any of the I/O
299+
/// error kinds cannot be `match`ed on, and will only match a wildcard (`_`) pattern.
300+
/// New [`ErrorKind`]s might be added in the future for some of those.
301+
#[stable(feature = "rust1", since = "1.0.0")]
302+
Other,
303+
297304
/// Any I/O error from the standard library that's not part of this list.
298305
///
299306
/// Errors that are `Uncategorized` now may move to a different or a new
@@ -307,23 +314,24 @@ pub enum ErrorKind {
307314
impl ErrorKind {
308315
pub(crate) fn as_str(&self) -> &'static str {
309316
use ErrorKind::*;
317+
// Strictly alphabetical, please. (Sadly rustfmt cannot do this yet.)
310318
match *self {
311319
AddrInUse => "address in use",
312320
AddrNotAvailable => "address not available",
313321
AlreadyExists => "entity already exists",
314322
ArgumentListTooLong => "argument list too long",
315323
BrokenPipe => "broken pipe",
316-
ResourceBusy => "resource busy",
317324
ConnectionAborted => "connection aborted",
318325
ConnectionRefused => "connection refused",
319326
ConnectionReset => "connection reset",
320327
CrossesDevices => "cross-device link or rename",
321328
Deadlock => "deadlock",
322329
DirectoryNotEmpty => "directory not empty",
323330
ExecutableFileBusy => "executable file busy",
331+
FileTooLarge => "file too large",
324332
FilenameTooLong => "filename too long",
333+
FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)",
325334
FilesystemQuotaExceeded => "filesystem quota exceeded",
326-
FileTooLarge => "file too large",
327335
HostUnreachable => "host unreachable",
328336
Interrupted => "operation interrupted",
329337
InvalidData => "invalid data",
@@ -332,16 +340,16 @@ impl ErrorKind {
332340
NetworkDown => "network down",
333341
NetworkUnreachable => "network unreachable",
334342
NotADirectory => "not a directory",
335-
StorageFull => "no storage space",
336343
NotConnected => "not connected",
337344
NotFound => "entity not found",
345+
NotSeekable => "seek on unseekable file",
338346
Other => "other error",
339347
OutOfMemory => "out of memory",
340348
PermissionDenied => "permission denied",
341349
ReadOnlyFilesystem => "read-only filesystem or storage medium",
350+
ResourceBusy => "resource busy",
342351
StaleNetworkFileHandle => "stale network file handle",
343-
FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)",
344-
NotSeekable => "seek on unseekable file",
352+
StorageFull => "no storage space",
345353
TimedOut => "timed out",
346354
TooManyLinks => "too many links",
347355
Uncategorized => "uncategorized error",

0 commit comments

Comments
 (0)