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``
This commit is contained in:
commit
aeabe34d79
@ -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!"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user