Skip to content

Commit

Permalink
Rollup merge of #106964 - workingjubilee:crouching-ioerror-hidden-doc…
Browse files Browse the repository at this point in the history
…umentation, r=ChrisDenton

Clarify `Error::last_os_error` can be weird

Fundamentally, querying the OS for error codes is a process that is deeply subject to the whims of chance and fortune. We can account for OS, but not for every combination of platform APIs. A compiled binary may not recognize new errors introduced years later. We should clarify a few especially odd situations, and what they mean: We can effectively promise nothing... if you ask for Rust to decode errors where none have occurred.

This allows removing mention of ErrorKind::Uncategorized.
That error variant is hidden deliberately, so we should not explicitly mention it.

This fixes #106937.

Since you had an opinion also: Does this solution seem acceptable?
r? ``@ChrisDenton``
  • Loading branch information
matthiaskrgr authored Mar 23, 2023
2 parents df7fd99 + 0f32fd8 commit aeabe34
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions library/std/src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,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:
// `Other` and `Uncategorized` should remain at the end:
//
/// A custom error that does not fall under any other I/O error kind.
///
Expand Down Expand Up @@ -882,6 +882,13 @@ impl Error {

/// Returns the corresponding [`ErrorKind`] for this error.
///
/// This may be a value set by Rust code constructing custom `io::Error`s,
/// or if this `io::Error` was sourced from the operating system,
/// it will be a value inferred from the system's error encoding.
/// See [`last_os_error`] for more details.
///
/// [`last_os_error`]: Error::last_os_error
///
/// # Examples
///
/// ```
Expand All @@ -892,7 +899,8 @@ impl Error {
/// }
///
/// fn main() {
/// // Will print "Uncategorized".
/// // As no error has (visibly) occurred, this may print anything!
/// // It likely prints a placeholder for unidentified (non-)errors.
/// print_error(Error::last_os_error());
/// // Will print "AddrInUse".
/// print_error(Error::new(ErrorKind::AddrInUse, "oh no!"));
Expand Down

0 comments on commit aeabe34

Please sign in to comment.