about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-05-01 04:22:53 +0000
committerbors <bors@rust-lang.org>2015-05-01 04:22:53 +0000
commit5c710b593b429d39ea01375172a9ce968f43ab26 (patch)
treede78a15e84d7f97517b8f23ca7bf8c01634a3cd5 /src/libcore
parentc634ec2e88a85d7f553ec0d6746e24a886bc6fd4 (diff)
parenta5762625a168f195afbc5b74d674a93f8c692a8e (diff)
downloadrust-5c710b593b429d39ea01375172a9ce968f43ab26.tar.gz
rust-5c710b593b429d39ea01375172a9ce968f43ab26.zip
Auto merge of #24793 - aturon:io-error-any, r=alexcrichton
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

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

This commit furthermore marks `Reflect` as stable, since we are already
essentially committed to it via `Any`. Note that in the future, if we
determine that the parametricity aspects of `Reflect` are not needed, we
can deprecate the trait and provide a blanket implementation for it
for *all* types (rather than by using OIBIT), which would allow all
mentions of `Reflect` to be dropped over time. So there is not a strong
commitment here.

[breaking-change]

r? @alexcrichton 
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/any.rs6
-rw-r--r--src/libcore/marker.rs2
2 files changed, 4 insertions, 4 deletions
diff --git a/src/libcore/any.rs b/src/libcore/any.rs
index 85b8accadf3..a65394f5268 100644
--- a/src/libcore/any.rs
+++ b/src/libcore/any.rs
@@ -97,9 +97,7 @@ pub trait Any: Reflect + 'static {
     fn get_type_id(&self) -> TypeId;
 }
 
-impl<T> Any for T
-    where T: Reflect + 'static
-{
+impl<T: Reflect + 'static> Any for T {
     fn get_type_id(&self) -> TypeId { TypeId::of::<T>() }
 }
 
@@ -222,7 +220,7 @@ impl TypeId {
     /// Returns the `TypeId` of the type this generic function has been
     /// instantiated with
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn of<T: ?Sized + Any>() -> TypeId {
+    pub fn of<T: ?Sized + Reflect + 'static>() -> TypeId {
         TypeId {
             t: unsafe { intrinsics::type_id::<T>() },
         }
diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs
index 44e5390098b..e8c7045141d 100644
--- a/src/libcore/marker.rs
+++ b/src/libcore/marker.rs
@@ -416,6 +416,8 @@ mod impls {
 #[rustc_reflect_like]
 #[unstable(feature = "core", reason = "requires RFC and more experience")]
 #[allow(deprecated)]
+#[rustc_on_unimplemented = "`{Self}` does not implement `Any`; \
+                            ensure all type parameters are bounded by `Any`"]
 pub trait Reflect {}
 
 impl Reflect for .. { }