diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 210a9ec718315..7e38a1a3b7b75 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -742,6 +742,12 @@ impl Error { } } } +#[stable(feature = "io_error_eq_errorkind", since = "1.60.0")] +impl PartialEq for Error { + fn eq(&self, other: &ErrorKind) -> bool { + self.kind() == *other + } +} impl fmt::Debug for Repr { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/library/std/src/io/error/tests.rs b/library/std/src/io/error/tests.rs index 5098a46313de3..8c5c237d21c10 100644 --- a/library/std/src/io/error/tests.rs +++ b/library/std/src/io/error/tests.rs @@ -67,3 +67,9 @@ fn test_const() { assert!(format!("{:?}", E).contains("\"hello\"")); assert!(format!("{:?}", E).contains("NotFound")); } + +#[test] +fn test_eq_errorkind() { + let error = Error::new(ErrorKind::NotFound, "hello"); + assert_eq!(error, ErrorKind::NotFound); +}