summary refs log tree commit diff
path: root/src/libstd/sys/common
diff options
context:
space:
mode:
authorAaron Turon <aturon@mozilla.com>2015-04-24 14:34:57 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-05-05 10:57:01 -0700
commit279eaabfda25072f3ba20d4c8ea5fdd4f29382ea (patch)
tree93f4e39f0e6a52956ed08a0dae1086f806972262 /src/libstd/sys/common
parent850151a75709f146addd30bbbf1f23d384f0b381 (diff)
downloadrust-279eaabfda25072f3ba20d4c8ea5fdd4f29382ea.tar.gz
rust-279eaabfda25072f3ba20d4c8ea5fdd4f29382ea.zip
Add downcasting to std::error::Error
This commit brings the `Error` trait in line with the [Error interoperation
RFC](https://github.com/rust-lang/rfcs/pull/201) by adding downcasting,
which has long been intended. This change means that for any `Error`
trait objects that are `'static`, you can downcast to concrete error
types.

To make this work, it is necessary for `Error` to inherit from
`Reflect` (which is currently used to mark concrete types as "permitted
for reflection, aka downcasting"). This is a breaking change: it means
that impls like

```rust
impl<T> Error for MyErrorType<T> { ... }
```

must change to something like

```rust
impl<T: Reflect> Error for MyErrorType<T> { ... }
```

except that `Reflect` is currently unstable (and should remain so for
the time being). For now, code can instead bound by `Any`:

```rust
impl<T: Any> Error for MyErrorType<T> { ... }
```

which *is* stable and has `Reflect` as a super trait. The downside is
that this imposes a `'static` constraint, but that only
constrains *when* `Error` is implemented -- it does not actually
constrain the types that can implement `Error`.

[breaking-change]

Conflicts:
	src/libcore/marker.rs
Diffstat (limited to 'src/libstd/sys/common')
-rw-r--r--src/libstd/sys/common/poison.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/libstd/sys/common/poison.rs b/src/libstd/sys/common/poison.rs
index 6deb4a48007..6c59231c23a 100644
--- a/src/libstd/sys/common/poison.rs
+++ b/src/libstd/sys/common/poison.rs
@@ -10,6 +10,7 @@
 
 use prelude::v1::*;
 
+use marker::Reflect;
 use cell::UnsafeCell;
 use error::{Error};
 use fmt;
@@ -109,7 +110,7 @@ impl<T> fmt::Display for PoisonError<T> {
     }
 }
 
-impl<T: Send> Error for PoisonError<T> {
+impl<T: Send + Reflect> Error for PoisonError<T> {
     fn description(&self) -> &str {
         "poisoned lock: another task failed inside"
     }
@@ -155,13 +156,13 @@ impl<T> fmt::Debug for TryLockError<T> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T: Send> fmt::Display for TryLockError<T> {
+impl<T: Send + Reflect> fmt::Display for TryLockError<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         self.description().fmt(f)
     }
 }
 
-impl<T: Send> Error for TryLockError<T> {
+impl<T: Send + Reflect> Error for TryLockError<T> {
     fn description(&self) -> &str {
         match *self {
             TryLockError::Poisoned(ref p) => p.description(),