Skip to content

Commit fb5d3c1

Browse files
committed
Stabilize Any::get_type_id and rename to type_id
FCP: rust-lang#27745 (comment)
1 parent 7001537 commit fb5d3c1

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/libcore/any.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,24 @@ pub trait Any: 'static {
8181
/// # Examples
8282
///
8383
/// ```
84-
/// #![feature(get_type_id)]
85-
///
8684
/// use std::any::{Any, TypeId};
8785
///
8886
/// fn is_string(s: &dyn Any) -> bool {
89-
/// TypeId::of::<String>() == s.get_type_id()
87+
/// TypeId::of::<String>() == s.type_id()
9088
/// }
9189
///
9290
/// fn main() {
9391
/// assert_eq!(is_string(&0), false);
9492
/// assert_eq!(is_string(&"cookie monster".to_string()), true);
9593
/// }
9694
/// ```
97-
#[unstable(feature = "get_type_id",
98-
reason = "this method will likely be replaced by an associated static",
99-
issue = "27745")]
100-
fn get_type_id(&self) -> TypeId;
95+
#[stable(feature = "get_type_id", since = "1.34.0")]
96+
fn type_id(&self) -> TypeId;
10197
}
10298

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

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

163159
// Get TypeId of the type in the trait object
164-
let boxed = self.get_type_id();
160+
let concrete = self.type_id();
165161

166162
// Compare both TypeIds on equality
167-
t == boxed
163+
t == concrete
168164
}
169165

170166
/// Returns some reference to the boxed value if it is of type `T`, or

src/test/ui/traits/trait-privacy.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// compile-pass
2-
#![feature(get_type_id)]
32
#![allow(dead_code)]
43
mod foo {
54
pub use self::bar::T;
@@ -18,7 +17,7 @@ fn g() {
1817

1918
fn f() {
2019
let error = ::std::thread::spawn(|| {}).join().unwrap_err();
21-
error.get_type_id(); // Regression test for #21670
20+
error.type_id(); // Regression test for #21670
2221
}
2322

2423

0 commit comments

Comments
 (0)