diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-03-23 19:55:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-23 19:55:42 +0100 |
| commit | aeabe34d79a61f772e64e5fba3f1f09d4a9c9e5e (patch) | |
| tree | 59c68d4dbe172c49a771a11e3b9002584dceef5d | |
| parent | df7fd9995f10627f25ccb325f693a11b3395a73c (diff) | |
| parent | 0f32fd8484d3282648dc18985b7d29abad2d6b70 (diff) | |
| download | rust-aeabe34d79a61f772e64e5fba3f1f09d4a9c9e5e.tar.gz rust-aeabe34d79a61f772e64e5fba3f1f09d4a9c9e5e.zip | |
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``
| -rw-r--r-- | library/std/src/io/error.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 7f07e4fddef..1cedd6eedfa 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -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. /// @@ -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 /// /// ``` @@ -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!")); |
