Skip to content
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
16 changes: 6 additions & 10 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,24 @@ pub trait Any: 'static {
/// # Examples
///
/// ```
/// #![feature(get_type_id)]
///
/// use std::any::{Any, TypeId};
///
/// fn is_string(s: &dyn Any) -> bool {
/// TypeId::of::<String>() == s.get_type_id()
/// TypeId::of::<String>() == s.type_id()
/// }
///
/// fn main() {
/// assert_eq!(is_string(&0), false);
/// assert_eq!(is_string(&"cookie monster".to_string()), true);
/// }
/// ```
#[unstable(feature = "get_type_id",
reason = "this method will likely be replaced by an associated static",
issue = "27745")]
fn get_type_id(&self) -> TypeId;
#[stable(feature = "get_type_id", since = "1.34.0")]
fn type_id(&self) -> TypeId;
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: 'static + ?Sized > Any for T {
fn get_type_id(&self) -> TypeId { TypeId::of::<T>() }
fn type_id(&self) -> TypeId { TypeId::of::<T>() }
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -161,10 +157,10 @@ impl dyn Any {
let t = TypeId::of::<T>();

// Get TypeId of the type in the trait object
let boxed = self.get_type_id();
let concrete = self.type_id();

// Compare both TypeIds on equality
t == boxed
t == concrete
}

/// Returns some reference to the boxed value if it is of type `T`, or
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/traits/trait-privacy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// compile-pass
#![feature(get_type_id)]
#![allow(dead_code)]
mod foo {
pub use self::bar::T;
Expand All @@ -18,7 +17,7 @@ fn g() {

fn f() {
let error = ::std::thread::spawn(|| {}).join().unwrap_err();
error.get_type_id(); // Regression test for #21670
error.type_id(); // Regression test for #21670
}


Expand Down