diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs index cc8c331ef3997..e28c3c37b6f76 100644 --- a/src/libstd/sync/poison.rs +++ b/src/libstd/sync/poison.rs @@ -11,7 +11,7 @@ use prelude::v1::*; use cell::UnsafeCell; -use error::FromError; +use error::{Error, FromError}; use fmt; use thread::Thread; @@ -92,7 +92,13 @@ pub type TryLockResult = Result>; impl fmt::Show for PoisonError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - "poisoned lock: another task failed inside".fmt(f) + self.description().fmt(f) + } +} + +impl Error for PoisonError { + fn description(&self) -> &str { + "poisoned lock: another task failed inside" } } @@ -126,11 +132,22 @@ impl FromError> for TryLockError { impl fmt::Show for TryLockError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.description().fmt(f) + } +} + +impl Error for TryLockError { + fn description(&self) -> &str { + match *self { + TryLockError::Poisoned(ref p) => p.description(), + TryLockError::WouldBlock => "try_lock failed because the operation would block" + } + } + + fn cause(&self) -> Option<&Error> { match *self { - TryLockError::Poisoned(ref p) => p.fmt(f), - TryLockError::WouldBlock => { - "try_lock failed because the operation would block".fmt(f) - } + TryLockError::Poisoned(ref p) => Some(p), + _ => None } } }