Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify Error::last_os_error can be weird #106964

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions library/std/src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,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 @@ -871,6 +871,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 @@ -881,7 +888,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