Skip to content

Commit d709ec4

Browse files
committed
Rollup merge of #23876 - alexcrichton:stabilize-any, r=aturon
This commit stabilizes the following APIs: * `TypeId::of` - now that it has an `Any` bound it's ready to be stable. * `Box<Any>::downcast` - now that an inherent impl on `Box<Any>` as well as `Box<Any+Send>` 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]
2 parents d10601a + f19e763 commit d709ec4

File tree

5 files changed

+7
-25
lines changed

5 files changed

+7
-25
lines changed

src/liballoc/boxed.rs

+6-20
Original file line numberDiff line numberDiff line change
@@ -233,24 +233,10 @@ impl<T: ?Sized + Hash> Hash for Box<T> {
233233
}
234234
}
235235

236-
/// Extension methods for an owning `Any` trait object.
237-
#[unstable(feature = "alloc",
238-
reason = "this trait will likely disappear once compiler bugs blocking \
239-
a direct impl on `Box<Any>` have been fixed ")]
240-
// FIXME(#18737): this should be a direct impl on `Box<Any>`. If you're
241-
// removing this please make sure that you can downcase on
242-
// `Box<Any + Send>` as well as `Box<Any>`
243-
pub trait BoxAny {
244-
/// Returns the boxed value if it is of type `T`, or
245-
/// `Err(Self)` if it isn't.
246-
#[stable(feature = "rust1", since = "1.0.0")]
247-
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>>;
248-
}
249-
250-
#[stable(feature = "rust1", since = "1.0.0")]
251-
impl BoxAny for Box<Any> {
236+
impl Box<Any> {
252237
#[inline]
253-
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
238+
#[stable(feature = "rust1", since = "1.0.0")]
239+
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
254240
if self.is::<T>() {
255241
unsafe {
256242
// Get the raw representation of the trait object
@@ -267,10 +253,10 @@ impl BoxAny for Box<Any> {
267253
}
268254
}
269255

270-
#[stable(feature = "rust1", since = "1.0.0")]
271-
impl BoxAny for Box<Any+Send> {
256+
impl Box<Any+Send> {
272257
#[inline]
273-
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
258+
#[stable(feature = "rust1", since = "1.0.0")]
259+
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
274260
<Box<Any>>::downcast(self)
275261
}
276262
}

src/liballoc/boxed_test.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use core::clone::Clone;
1717

1818
use std::boxed;
1919
use std::boxed::Box;
20-
use std::boxed::BoxAny;
2120

2221
#[test]
2322
fn test_owned_clone() {

src/libcore/any.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ pub struct TypeId {
202202
impl TypeId {
203203
/// Returns the `TypeId` of the type this generic function has been
204204
/// instantiated with
205-
#[unstable(feature = "core",
206-
reason = "may grow a `Reflect` bound soon via marker traits")]
205+
#[stable(feature = "rust1", since = "1.0.0")]
207206
pub fn of<T: ?Sized + Any>() -> TypeId {
208207
TypeId {
209208
t: unsafe { intrinsics::type_id::<T>() },

src/libstd/thread/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,6 @@ mod test {
810810

811811
use any::Any;
812812
use sync::mpsc::{channel, Sender};
813-
use boxed::BoxAny;
814813
use result;
815814
use std::old_io::{ChanReader, ChanWriter};
816815
use super::{Builder};

src/test/run-pass/unit-like-struct-drop-run.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#![feature(alloc)]
1616

17-
use std::boxed::BoxAny;
1817
use std::thread;
1918

2019
struct Foo;

0 commit comments

Comments
 (0)