Skip to content

Commit 856b90c

Browse files
committed
auto merge of #20393 : japaric/rust/impl-any, r=aturon
Needs a snapshot that contains PR #20385 r? @aturon
2 parents 7e3d115 + 5172b80 commit 856b90c

File tree

8 files changed

+12
-35
lines changed

8 files changed

+12
-35
lines changed

src/liballoc/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
#![stable]
1414

15-
use core::any::{Any, AnyRefExt};
15+
use core::any::Any;
1616
use core::clone::Clone;
1717
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
1818
use core::default::Default;

src/libcore/any.rs

+8-28
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
//!
3636
//! ```rust
3737
//! use std::fmt::Show;
38-
//! use std::any::{Any, AnyRefExt};
38+
//! use std::any::Any;
3939
//!
4040
//! // Logger function for any type that implements Show.
4141
//! fn log<T: Any+Show>(value: &T) {
@@ -102,24 +102,11 @@ impl<T: 'static> Any for T {
102102
// Implemented as three extension traits so that the methods can be generic.
103103
///////////////////////////////////////////////////////////////////////////////
104104

105-
/// Extension methods for a referenced `Any` trait object
106-
#[unstable = "this trait will not be necessary once DST lands, it will be a \
107-
part of `impl Any`"]
108-
pub trait AnyRefExt<'a> {
105+
impl Any {
109106
/// Returns true if the boxed type is the same as `T`
110107
#[stable]
111-
fn is<T: 'static>(self) -> bool;
112-
113-
/// Returns some reference to the boxed value if it is of type `T`, or
114-
/// `None` if it isn't.
115-
#[unstable = "naming conventions around acquiring references may change"]
116-
fn downcast_ref<T: 'static>(self) -> Option<&'a T>;
117-
}
118-
119-
#[stable]
120-
impl<'a> AnyRefExt<'a> for &'a Any {
121108
#[inline]
122-
fn is<T: 'static>(self) -> bool {
109+
pub fn is<T: 'static>(&self) -> bool {
123110
// Get TypeId of the type this function is instantiated with
124111
let t = TypeId::of::<T>();
125112

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

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

149-
/// Extension methods for a mutable referenced `Any` trait object
150-
#[unstable = "this trait will not be necessary once DST lands, it will be a \
151-
part of `impl Any`"]
152-
pub trait AnyMutRefExt<'a> {
153138
/// Returns some mutable reference to the boxed value if it is of type `T`, or
154139
/// `None` if it isn't.
155140
#[unstable = "naming conventions around acquiring references may change"]
156-
fn downcast_mut<T: 'static>(self) -> Option<&'a mut T>;
157-
}
158-
159-
#[stable]
160-
impl<'a> AnyMutRefExt<'a> for &'a mut Any {
161141
#[inline]
162-
fn downcast_mut<T: 'static>(self) -> Option<&'a mut T> {
142+
pub fn downcast_mut<'a, T: 'static>(&'a mut self) -> Option<&'a mut T> {
163143
if self.is::<T>() {
164144
unsafe {
165145
// Get the raw representation of the trait object

src/librustc_driver/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ use rustc::lint;
5454
use rustc::metadata;
5555
use rustc::DIAGNOSTICS;
5656

57-
use std::any::AnyRefExt;
5857
use std::cmp::Ordering::Equal;
5958
use std::io;
6059
use std::iter::repeat;

src/libstd/failure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
use prelude::v1::*;
1414

15-
use any::{Any, AnyRefExt};
15+
use any::Any;
1616
use cell::RefCell;
1717
use io::IoResult;
1818
use rt::{backtrace, unwind};

src/libstd/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl<T: Send> Drop for JoinGuard<T> {
435435
mod test {
436436
use prelude::v1::*;
437437

438-
use any::{Any, AnyRefExt};
438+
use any::Any;
439439
use sync::mpsc::{channel, Sender};
440440
use boxed::BoxAny;
441441
use result;

src/libtest/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use serialize::{json, Decodable, Encodable};
5858
use term::Terminal;
5959
use term::color::{Color, RED, YELLOW, GREEN, CYAN};
6060

61-
use std::any::{Any, AnyRefExt};
61+
use std::any::Any;
6262
use std::cmp;
6363
use std::collections::BTreeMap;
6464
use std::f64;

src/test/compile-fail/kindck-inherited-copy-bound.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// Test that Copy bounds inherited by trait are checked.
1212

1313
use std::any::Any;
14-
use std::any::AnyRefExt;
1514

1615
trait Foo : Copy {
1716
}

src/test/run-pass/object-one-type-two-traits.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// traits.
1313

1414
use std::any::Any;
15-
use std::any::AnyRefExt;
1615

1716
trait Wrap {
1817
fn get(&self) -> int;

0 commit comments

Comments
 (0)