Skip to content

Commit

Permalink
Rollup merge of rust-lang#21331 - michaelsproul:sync-error-impls, r=a…
Browse files Browse the repository at this point in the history
…lexcrichton

Two errors in `std::sync` are currently missing implementations of the standard error trait because they contain types which aren't `Send`.

This PR therefore requires rust-lang#21312.
  • Loading branch information
barosl committed Jan 20, 2015
2 parents b3f6e82 + ffdf111 commit efa8360
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/libstd/sync/poison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use prelude::v1::*;

use cell::UnsafeCell;
use error::FromError;
use error::{Error, FromError};
use fmt;
use thread::Thread;

Expand Down Expand Up @@ -92,7 +92,13 @@ pub type TryLockResult<Guard> = Result<Guard, TryLockError<Guard>>;

impl<T> fmt::Show for PoisonError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
"poisoned lock: another task failed inside".fmt(f)
self.description().fmt(f)
}
}

impl<T> Error for PoisonError<T> {
fn description(&self) -> &str {
"poisoned lock: another task failed inside"
}
}

Expand Down Expand Up @@ -126,11 +132,22 @@ impl<T> FromError<PoisonError<T>> for TryLockError<T> {

impl<T> fmt::Show for TryLockError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.description().fmt(f)
}
}

impl<T> Error for TryLockError<T> {
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
}
}
}
Expand Down

0 comments on commit efa8360

Please sign in to comment.