diff options
| author | Aaron Turon <aturon@mozilla.com> | 2015-04-24 14:34:57 -0700 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2015-04-30 18:20:22 -0700 |
| commit | a5762625a168f195afbc5b74d674a93f8c692a8e (patch) | |
| tree | 1d5cd7de1e4894a220c1d34578defbdc0c305d63 /src/libstd/sync | |
| parent | e962870420fef19e8f23a299dbe7499aca1656a5 (diff) | |
| download | rust-a5762625a168f195afbc5b74d674a93f8c692a8e.tar.gz rust-a5762625a168f195afbc5b74d674a93f8c692a8e.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]
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/mpsc/mod.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 61932225d79..965ad74fb60 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -272,6 +272,7 @@ use error; use fmt; use mem; use cell::UnsafeCell; +use marker::Reflect; pub use self::select::{Select, Handle}; use self::select::StartResult; @@ -955,8 +956,7 @@ impl<T> fmt::Display for SendError<T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: Send> error::Error for SendError<T> { - +impl<T: Send + Reflect> error::Error for SendError<T> { fn description(&self) -> &str { "sending on a closed channel" } @@ -991,7 +991,7 @@ impl<T> fmt::Display for TrySendError<T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: Send> error::Error for TrySendError<T> { +impl<T: Send + Reflect> error::Error for TrySendError<T> { fn description(&self) -> &str { match *self { |
