From a5762625a168f195afbc5b74d674a93f8c692a8e Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Fri, 24 Apr 2015 14:34:57 -0700 Subject: 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 Error for MyErrorType { ... } ``` must change to something like ```rust impl Error for MyErrorType { ... } ``` except that `Reflect` is currently unstable (and should remain so for the time being). For now, code can instead bound by `Any`: ```rust impl Error for MyErrorType { ... } ``` 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] --- src/libstd/sync/mpsc/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libstd/sync') 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 fmt::Display for SendError { } #[stable(feature = "rust1", since = "1.0.0")] -impl error::Error for SendError { - +impl error::Error for SendError { fn description(&self) -> &str { "sending on a closed channel" } @@ -991,7 +991,7 @@ impl fmt::Display for TrySendError { } #[stable(feature = "rust1", since = "1.0.0")] -impl error::Error for TrySendError { +impl error::Error for TrySendError { fn description(&self) -> &str { match *self { -- cgit 1.4.1-3-g733a5