Skip to content

remove Any[Mut]RefExt traits in favor of impl Any #20393

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
Jan 4, 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
2 changes: 1 addition & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#![stable]

use core::any::{Any, AnyRefExt};
use core::any::Any;
use core::clone::Clone;
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
use core::default::Default;
Expand Down
36 changes: 8 additions & 28 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
//!
//! ```rust
//! use std::fmt::Show;
//! use std::any::{Any, AnyRefExt};
//! use std::any::Any;
//!
//! // Logger function for any type that implements Show.
//! fn log<T: Any+Show>(value: &T) {
Expand Down Expand Up @@ -102,24 +102,11 @@ impl<T: 'static> Any for T {
// Implemented as three extension traits so that the methods can be generic.
///////////////////////////////////////////////////////////////////////////////

/// Extension methods for a referenced `Any` trait object
#[unstable = "this trait will not be necessary once DST lands, it will be a \
part of `impl Any`"]
pub trait AnyRefExt<'a> {
impl Any {
/// Returns true if the boxed type is the same as `T`
#[stable]
fn is<T: 'static>(self) -> bool;

/// Returns some reference to the boxed value if it is of type `T`, or
/// `None` if it isn't.
#[unstable = "naming conventions around acquiring references may change"]
fn downcast_ref<T: 'static>(self) -> Option<&'a T>;
}

#[stable]
impl<'a> AnyRefExt<'a> for &'a Any {
#[inline]
fn is<T: 'static>(self) -> bool {
pub fn is<T: 'static>(&self) -> bool {
// Get TypeId of the type this function is instantiated with
let t = TypeId::of::<T>();

Expand All @@ -130,8 +117,11 @@ impl<'a> AnyRefExt<'a> for &'a Any {
t == boxed
}

/// Returns some reference to the boxed value if it is of type `T`, or
/// `None` if it isn't.
#[unstable = "naming conventions around acquiring references may change"]
#[inline]
fn downcast_ref<T: 'static>(self) -> Option<&'a T> {
pub fn downcast_ref<'a, T: 'static>(&'a self) -> Option<&'a T> {
if self.is::<T>() {
unsafe {
// Get the raw representation of the trait object
Expand All @@ -144,22 +134,12 @@ impl<'a> AnyRefExt<'a> for &'a Any {
None
}
}
}

/// Extension methods for a mutable referenced `Any` trait object
#[unstable = "this trait will not be necessary once DST lands, it will be a \
part of `impl Any`"]
pub trait AnyMutRefExt<'a> {
/// Returns some mutable reference to the boxed value if it is of type `T`, or
/// `None` if it isn't.
#[unstable = "naming conventions around acquiring references may change"]
fn downcast_mut<T: 'static>(self) -> Option<&'a mut T>;
}

#[stable]
impl<'a> AnyMutRefExt<'a> for &'a mut Any {
#[inline]
fn downcast_mut<T: 'static>(self) -> Option<&'a mut T> {
pub fn downcast_mut<'a, T: 'static>(&'a mut self) -> Option<&'a mut T> {
if self.is::<T>() {
unsafe {
// Get the raw representation of the trait object
Expand Down
1 change: 0 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use rustc::lint;
use rustc::metadata;
use rustc::DIAGNOSTICS;

use std::any::AnyRefExt;
use std::cmp::Ordering::Equal;
use std::io;
use std::iter::repeat;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use prelude::v1::*;

use any::{Any, AnyRefExt};
use any::Any;
use cell::RefCell;
use io::IoResult;
use rt::{backtrace, unwind};
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl<T: Send> Drop for JoinGuard<T> {
mod test {
use prelude::v1::*;

use any::{Any, AnyRefExt};
use any::Any;
use sync::mpsc::{channel, Sender};
use boxed::BoxAny;
use result;
Expand Down
2 changes: 1 addition & 1 deletion src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use serialize::{json, Decodable, Encodable};
use term::Terminal;
use term::color::{Color, RED, YELLOW, GREEN, CYAN};

use std::any::{Any, AnyRefExt};
use std::any::Any;
use std::cmp;
use std::collections::BTreeMap;
use std::f64;
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/kindck-inherited-copy-bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// Test that Copy bounds inherited by trait are checked.

use std::any::Any;
use std::any::AnyRefExt;

trait Foo : Copy {
}
Expand Down
1 change: 0 additions & 1 deletion src/test/run-pass/object-one-type-two-traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// traits.

use std::any::Any;
use std::any::AnyRefExt;

trait Wrap {
fn get(&self) -> int;
Expand Down