diff options
| author | bors <bors@rust-lang.org> | 2018-02-04 22:58:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-02-04 22:58:10 +0000 |
| commit | e7e982ac03b496dd4d4b5c182fdcd5fb4f2b5470 (patch) | |
| tree | 3495f1e9721731384fae0e1c2a6209fd1402a76f /src/libcore | |
| parent | 0c6091fbd0eee290c651f73be899f221eeab3c05 (diff) | |
| parent | e17ebdf344401c265ade3b02bb68df0d0485d71a (diff) | |
| download | rust-e7e982ac03b496dd4d4b5c182fdcd5fb4f2b5470.tar.gz rust-e7e982ac03b496dd4d4b5c182fdcd5fb4f2b5470.zip | |
Auto merge of #47998 - kennytm:rollup, r=kennytm
Rollup of 10 pull requests - Successful merges: #47862, #47877, #47896, #47912, #47947, #47958, #47978, #47996, #47999, #47892 - Failed merges:
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/any.rs | 27 | ||||
| -rw-r--r-- | src/libcore/lib.rs | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 338e5c7fd95..566bfe2a3fb 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -367,9 +367,36 @@ impl TypeId { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] pub fn of<T: ?Sized + 'static>() -> TypeId { TypeId { t: unsafe { intrinsics::type_id::<T>() }, } } + + /// Returns the `TypeId` of the type this generic function has been + /// instantiated with. + /// + /// # Examples + /// + /// ``` + /// use std::any::{Any, TypeId}; + /// + /// fn is_string<T: ?Sized + Any>(_s: &T) -> bool { + /// TypeId::of::<String>() == TypeId::of::<T>() + /// } + /// + /// fn main() { + /// assert_eq!(is_string(&0), false); + /// assert_eq!(is_string(&"cookie monster".to_string()), true); + /// } + /// ``` + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature="const_type_id")] + #[cfg(not(stage0))] + pub const fn of<T: ?Sized + 'static>() -> TypeId { + TypeId { + t: unsafe { intrinsics::type_id::<T>() }, + } + } } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 2e1f925c49a..59a296c2a76 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -91,6 +91,7 @@ #![feature(untagged_unions)] #![feature(unwind_attributes)] #![feature(doc_spotlight)] +#![feature(rustc_const_unstable)] #[prelude_import] #[allow(unused)] |
