Skip to content

Commit

Permalink
error: drop 'source' impl
Browse files Browse the repository at this point in the history
We can either write an underlying error's display string in our
own Display impl OR we can return it as a source. We can't do
both, otherwise we wind up with repeating error messages when using
today's error helper libraries (like anyhow).

Since the error types are either exposed or already offer a way
to get the underlying error, we just drop the 'source' impl.
  • Loading branch information
BurntSushi committed Feb 14, 2023
1 parent 9ab8311 commit 022ac05
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,7 @@ impl From<Error> for io::Error {
}
}

impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match *self.0 {
ErrorKind::Io(ref err) => Some(err),
ErrorKind::Utf8 { ref err, .. } => Some(err),
ErrorKind::UnequalLengths { .. } => None,
ErrorKind::Seek => None,
ErrorKind::Serialize(_) => None,
ErrorKind::Deserialize { ref err, .. } => Some(err),
_ => unreachable!(),
}
}
}
impl StdError for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -333,11 +321,7 @@ impl<W> IntoInnerError<W> {
}
}

impl<W: std::any::Any> StdError for IntoInnerError<W> {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
self.err.source()
}
}
impl<W: std::any::Any> StdError for IntoInnerError<W> {}

impl<W> fmt::Display for IntoInnerError<W> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down

0 comments on commit 022ac05

Please sign in to comment.