1
Fork 0

Auto merge of #85746 - m-ou-se:io-error-other, r=joshtriplett

Redefine `ErrorKind::Other` and stop using it in std.

This implements the idea I shared yesterday in the libs meeting when we were discussing how to handle adding new `ErrorKind`s to the standard library: This redefines `Other` to be for *user defined errors only*, and changes all uses of `Other` in the standard library to a `#[doc(hidden)]` and permanently `#[unstable]` `ErrorKind` that users can not match on. This ensures that adding `ErrorKind`s at a later point in time is not a breaking change, since the user couldn't match on these errors anyway. This way, we use the `#[non_exhaustive]` property of the enum in a more effective way.

Open questions:
- How do we check this change doesn't cause too much breakage? Will a crate run help and be enough?
- How do we ensure we don't accidentally start using `Other` again in the standard library? We don't have a `pub(not crate)` or `#[deprecated(in this crate only)]`.

cc https://github.com/rust-lang/rust/pull/79965

cc `@rust-lang/libs` `@ijackson`

r? `@dtolnay`
This commit is contained in:
bors 2021-07-02 09:01:42 +00:00
commit f9fa13f705
24 changed files with 99 additions and 74 deletions

View file

@ -38,7 +38,7 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> {
str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap().to_owned()
};
Err(io::Error::new(
io::ErrorKind::Other,
io::ErrorKind::Uncategorized,
&format!("failed to lookup address information: {}", detail)[..],
))
}
@ -178,7 +178,7 @@ impl Socket {
if pollfd.revents & libc::POLLHUP != 0 {
let e = self.take_error()?.unwrap_or_else(|| {
io::Error::new_const(
io::ErrorKind::Other,
io::ErrorKind::Uncategorized,
&"no error set after POLLHUP",
)
});