diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2019-01-22 14:25:27 +0100 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2019-01-22 14:25:27 +0100 |
| commit | fb5d3c1f379e42b9d31887b744982159a0dc651b (patch) | |
| tree | 60574b04aeb8c72cfb6cff7e0e25ea13964a5a20 | |
| parent | 70015373b4980fbfa10130de4b0ce041f5b5da8b (diff) | |
| download | rust-fb5d3c1f379e42b9d31887b744982159a0dc651b.tar.gz rust-fb5d3c1f379e42b9d31887b744982159a0dc651b.zip | |
Stabilize Any::get_type_id and rename to type_id
FCP: https://github.com/rust-lang/rust/issues/27745#issuecomment-373906749
| -rw-r--r-- | src/libcore/any.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/traits/trait-privacy.rs | 3 |
2 files changed, 7 insertions, 12 deletions
diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 6a863ff369a..2afd9e0c072 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -81,12 +81,10 @@ 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() { @@ -94,15 +92,13 @@ pub trait Any: 'static { /// 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>() } } /////////////////////////////////////////////////////////////////////////////// @@ -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 diff --git a/src/test/ui/traits/trait-privacy.rs b/src/test/ui/traits/trait-privacy.rs index 523211fea93..6254157e25d 100644 --- a/src/test/ui/traits/trait-privacy.rs +++ b/src/test/ui/traits/trait-privacy.rs @@ -1,5 +1,4 @@ // compile-pass -#![feature(get_type_id)] #![allow(dead_code)] mod foo { pub use self::bar::T; @@ -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 } |
