Skip to content

std: Stabilize the rest of Any/BoxAny #23876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,10 @@ impl<T: ?Sized + Hash> Hash for Box<T> {
}
}

/// 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<Any>` have been fixed ")]
// FIXME(#18737): this should be a direct impl on `Box<Any>`. If you're
// removing this please make sure that you can downcase on
// `Box<Any + Send>` as well as `Box<Any>`
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<T: Any>(self) -> Result<Box<T>, Box<Any>>;
}

#[stable(feature = "rust1", since = "1.0.0")]
impl BoxAny for Box<Any> {
impl Box<Any> {
#[inline]
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
if self.is::<T>() {
unsafe {
// Get the raw representation of the trait object
Expand All @@ -267,10 +253,10 @@ impl BoxAny for Box<Any> {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl BoxAny for Box<Any+Send> {
impl Box<Any+Send> {
#[inline]
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
<Box<Any>>::downcast(self)
}
}
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/boxed_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use core::clone::Clone;

use std::boxed;
use std::boxed::Box;
use std::boxed::BoxAny;

#[test]
fn test_owned_clone() {
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: ?Sized + Any>() -> TypeId {
TypeId {
t: unsafe { intrinsics::type_id::<T>() },
Expand Down
1 change: 0 additions & 1 deletion src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
1 change: 0 additions & 1 deletion src/test/run-pass/unit-like-struct-drop-run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#![feature(alloc)]

use std::boxed::BoxAny;
use std::thread;

struct Foo;
Expand Down