From f19e763e0824a73118ed715f526cb7bdd584d4c4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 30 Mar 2015 16:43:04 -0700 Subject: [PATCH] std: Stabilize the rest of Any/BoxAny This commit stabilizes the following APIs: * `TypeId::of` - now that it has an `Any` bound it's ready to be stable. * `Box::downcast` - now that an inherent impl on `Box` as well as `Box` is allowed the `BoxAny` trait is removed in favor of these inherent methods. This is a breaking change due to the removal of the `BoxAny` trait, but consumers can simply remove imports to fix crates. [breaking-change] --- src/liballoc/boxed.rs | 26 +++++-------------- src/liballoc/boxed_test.rs | 1 - src/libcore/any.rs | 3 +-- src/libstd/thread/mod.rs | 1 - .../run-pass/unit-like-struct-drop-run.rs | 1 - 5 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index f9bd0ab2f1e..48dce3d8815 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -233,24 +233,10 @@ impl Hash for Box { } } -/// Extension methods for an owning `Any` trait object. -#[unstable(feature = "alloc", - reason = "this trait will likely disappear once compiler bugs blocking \ - a direct impl on `Box` have been fixed ")] -// FIXME(#18737): this should be a direct impl on `Box`. If you're -// removing this please make sure that you can downcase on -// `Box` as well as `Box` -pub trait BoxAny { - /// Returns the boxed value if it is of type `T`, or - /// `Err(Self)` if it isn't. - #[stable(feature = "rust1", since = "1.0.0")] - fn downcast(self) -> Result, Box>; -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl BoxAny for Box { +impl Box { #[inline] - fn downcast(self) -> Result, Box> { + #[stable(feature = "rust1", since = "1.0.0")] + pub fn downcast(self) -> Result, Box> { if self.is::() { unsafe { // Get the raw representation of the trait object @@ -267,10 +253,10 @@ impl BoxAny for Box { } } -#[stable(feature = "rust1", since = "1.0.0")] -impl BoxAny for Box { +impl Box { #[inline] - fn downcast(self) -> Result, Box> { + #[stable(feature = "rust1", since = "1.0.0")] + pub fn downcast(self) -> Result, Box> { >::downcast(self) } } diff --git a/src/liballoc/boxed_test.rs b/src/liballoc/boxed_test.rs index bb1ff9428a7..682d5f407c4 100644 --- a/src/liballoc/boxed_test.rs +++ b/src/liballoc/boxed_test.rs @@ -17,7 +17,6 @@ use core::clone::Clone; use std::boxed; use std::boxed::Box; -use std::boxed::BoxAny; #[test] fn test_owned_clone() { diff --git a/src/libcore/any.rs b/src/libcore/any.rs index d3bc07b173a..0ffc4a229b5 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -202,8 +202,7 @@ pub struct TypeId { impl TypeId { /// Returns the `TypeId` of the type this generic function has been /// instantiated with - #[unstable(feature = "core", - reason = "may grow a `Reflect` bound soon via marker traits")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn of() -> TypeId { TypeId { t: unsafe { intrinsics::type_id::() }, diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 074030bd07b..863291ff542 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -810,7 +810,6 @@ mod test { use any::Any; use sync::mpsc::{channel, Sender}; - use boxed::BoxAny; use result; use std::old_io::{ChanReader, ChanWriter}; use super::{Builder}; diff --git a/src/test/run-pass/unit-like-struct-drop-run.rs b/src/test/run-pass/unit-like-struct-drop-run.rs index 9e1ced36402..c2db63ed251 100644 --- a/src/test/run-pass/unit-like-struct-drop-run.rs +++ b/src/test/run-pass/unit-like-struct-drop-run.rs @@ -14,7 +14,6 @@ #![feature(alloc)] -use std::boxed::BoxAny; use std::thread; struct Foo;