Skip to content

Commit aeabe34

Browse files
authored
Rollup merge of #106964 - workingjubilee:crouching-ioerror-hidden-documentation, 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``
2 parents df7fd99 + 0f32fd8 commit aeabe34

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

library/std/src/io/error.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub enum ErrorKind {
370370

371371
// "Unusual" error kinds which do not correspond simply to (sets
372372
// of) OS error codes, should be added just above this comment.
373-
// `Other` and `Uncategorised` should remain at the end:
373+
// `Other` and `Uncategorized` should remain at the end:
374374
//
375375
/// A custom error that does not fall under any other I/O error kind.
376376
///
@@ -882,6 +882,13 @@ impl Error {
882882

883883
/// Returns the corresponding [`ErrorKind`] for this error.
884884
///
885+
/// This may be a value set by Rust code constructing custom `io::Error`s,
886+
/// or if this `io::Error` was sourced from the operating system,
887+
/// it will be a value inferred from the system's error encoding.
888+
/// See [`last_os_error`] for more details.
889+
///
890+
/// [`last_os_error`]: Error::last_os_error
891+
///
885892
/// # Examples
886893
///
887894
/// ```
@@ -892,7 +899,8 @@ impl Error {
892899
/// }
893900
///
894901
/// fn main() {
895-
/// // Will print "Uncategorized".
902+
/// // As no error has (visibly) occurred, this may print anything!
903+
/// // It likely prints a placeholder for unidentified (non-)errors.
896904
/// print_error(Error::last_os_error());
897905
/// // Will print "AddrInUse".
898906
/// print_error(Error::new(ErrorKind::AddrInUse, "oh no!"));

0 commit comments

Comments
 (0)