about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-11-30 01:21:41 -0800
committerbors <bors@rust-lang.org>2013-11-30 01:21:41 -0800
commit156054f55cb1289d5828d09099a5a7ff5a44c5bd (patch)
tree82763921587e357ec69937c7e422f5322f31598e /src/libstd
parent80991bb578329ca921fdc910d9b6b064e8f521d2 (diff)
parent572635b76f878d3d08576b30a05c1db55d345347 (diff)
downloadrust-156054f55cb1289d5828d09099a5a7ff5a44c5bd.tar.gz
rust-156054f55cb1289d5828d09099a5a7ff5a44c5bd.zip
auto merge of #10722 : cmr/rust/type_id_opaque, r=alexcrichton
Closes #10594
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/any.rs31
-rw-r--r--src/libstd/unstable/intrinsics.rs25
2 files changed, 32 insertions, 24 deletions
diff --git a/src/libstd/any.rs b/src/libstd/any.rs
index e02bf9f4ba8..7af12bef7b5 100644
--- a/src/libstd/any.rs
+++ b/src/libstd/any.rs
@@ -12,22 +12,28 @@
 //! of any type.
 
 use cast::transmute;
+#[cfg(stage0)]
 use cmp::Eq;
 use option::{Option, Some, None};
+#[cfg(stage0)]
 use to_bytes::{IterBytes, Cb};
 use to_str::ToStr;
 use unstable::intrinsics;
 use util::Void;
+#[cfg(not(stage0))]
+use unstable::intrinsics::TypeId;
 
 ///////////////////////////////////////////////////////////////////////////////
 // TypeId
 ///////////////////////////////////////////////////////////////////////////////
 
 /// `TypeId` represents a globally unique identifier for a type
+#[cfg(stage0)]
 pub struct TypeId {
     priv t: u64,
 }
 
+#[cfg(stage0)]
 impl TypeId {
     /// Returns the `TypeId` of the type this generic function has been instantiated with
     #[inline]
@@ -36,6 +42,7 @@ impl TypeId {
     }
 }
 
+#[cfg(stage0)]
 impl Eq for TypeId {
     #[inline]
     fn eq(&self, &other: &TypeId) -> bool {
@@ -43,6 +50,7 @@ impl Eq for TypeId {
     }
 }
 
+#[cfg(stage0)]
 impl IterBytes for TypeId {
     fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
         self.t.iter_bytes(lsb0, f)
@@ -190,29 +198,6 @@ mod tests {
     static TEST: &'static str = "Test";
 
     #[test]
-    fn type_id() {
-        let (a, b, c) = (TypeId::of::<uint>(), TypeId::of::<&'static str>(),
-                         TypeId::of::<Test>());
-        let (d, e, f) = (TypeId::of::<uint>(), TypeId::of::<&'static str>(),
-                         TypeId::of::<Test>());
-
-        assert!(a != b);
-        assert!(a != c);
-        assert!(b != c);
-
-        assert_eq!(a, d);
-        assert_eq!(b, e);
-        assert_eq!(c, f);
-    }
-
-    #[test]
-    fn type_id_hash() {
-        let (a, b) = (TypeId::of::<uint>(), TypeId::of::<uint>());
-
-        assert_eq!(a.hash(), b.hash());
-    }
-
-    #[test]
     fn any_as_void_ptr() {
         let (a, b, c) = (~5u as ~Any, ~TEST as ~Any, ~Test as ~Any);
         let a_r: &Any = a;
diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs
index 89a51a5dddd..01b4225d70b 100644
--- a/src/libstd/unstable/intrinsics.rs
+++ b/src/libstd/unstable/intrinsics.rs
@@ -34,7 +34,7 @@ A quick refresher on memory ordering:
 
 // This is needed to prevent duplicate lang item definitions.
 #[cfg(test)]
-pub use realstd::unstable::intrinsics::{TyDesc, Opaque, TyVisitor};
+pub use realstd::unstable::intrinsics::{TyDesc, Opaque, TyVisitor, TypeId};
 
 pub type GlueFn = extern "Rust" fn(*i8);
 
@@ -313,7 +313,11 @@ extern "rust-intrinsic" {
     /// Gets an identifier which is globally unique to the specified type. This
     /// function will return the same value for a type regardless of whichever
     /// crate it is invoked in.
+    #[cfg(stage0)]
     pub fn type_id<T: 'static>() -> u64;
+    #[cfg(not(stage0))]
+    pub fn type_id<T: 'static>() -> TypeId;
+
 
     /// Create a value initialized to zero.
     ///
@@ -486,3 +490,22 @@ extern "rust-intrinsic" {
 #[cfg(target_endian = "big")]    pub fn to_be32(x: i32) -> i32 { x }
 #[cfg(target_endian = "little")] pub fn to_be64(x: i64) -> i64 { unsafe { bswap64(x) } }
 #[cfg(target_endian = "big")]    pub fn to_be64(x: i64) -> i64 { x }
+
+
+/// `TypeId` represents a globally unique identifier for a type
+#[lang="type_id"] // This needs to be kept in lockstep with the code in trans/intrinsic.rs and
+                  // middle/lang_items.rs
+#[deriving(Eq, IterBytes)]
+#[cfg(not(test))]
+pub struct TypeId {
+    priv t: u64,
+}
+
+#[cfg(not(test))]
+impl TypeId {
+    /// Returns the `TypeId` of the type this generic function has been instantiated with
+    #[cfg(not(stage0))]
+    pub fn of<T: 'static>() -> TypeId {
+        unsafe { type_id::<T>() }
+    }
+}