Skip to content

Commit aa0b7ac

Browse files
authored
Rollup merge of rust-lang#94273 - Dylan-DPC:doc/errorkind, r=joshtriplett
add matching doc to errorkind Rework of rust-lang#90706
2 parents 3cd1dc1 + 3f4b039 commit aa0b7ac

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/std/src/io/error.rs

+13
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ struct Custom {
141141
/// It is used with the [`io::Error`] type.
142142
///
143143
/// [`io::Error`]: Error
144+
///
145+
/// # Handling errors and matching on `ErrorKind`
146+
///
147+
/// In application code, use `match` for the `ErrorKind` values you are
148+
/// expecting; use `_` to match "all other errors".
149+
///
150+
/// In comprehensive and thorough tests that want to verify that a test doesn't
151+
/// return any known incorrect error kind, you may want to cut-and-paste the
152+
/// current full list of errors from here into your test code, and then match
153+
/// `_` as the correct case. This seems counterintuitive, but it will make your
154+
/// tests more robust. In particular, if you want to verify that your code does
155+
/// produce an unrecognized error kind, the robust solution is to check for all
156+
/// the recognized error kinds and fail in those cases.
144157
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
145158
#[stable(feature = "rust1", since = "1.0.0")]
146159
#[allow(deprecated)]

0 commit comments

Comments
 (0)