From 5b75e44fb01f0eda10ce8d8df92b80945d894768 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 30 Apr 2014 20:04:56 -0700 Subject: [PATCH] core: Inherit the intrinsics module --- src/{libstd => libcore}/intrinsics.rs | 4 +++- src/libcore/lib.rs | 4 ++++ src/libstd/fmt/mod.rs | 7 +++++++ src/libstd/hash/mod.rs | 8 ++++++++ src/libstd/lib.rs | 6 +++--- 5 files changed, 25 insertions(+), 4 deletions(-) rename src/{libstd => libcore}/intrinsics.rs (99%) diff --git a/src/libstd/intrinsics.rs b/src/libcore/intrinsics.rs similarity index 99% rename from src/libstd/intrinsics.rs rename to src/libcore/intrinsics.rs index c2d39ad990a8..770433c45212 100644 --- a/src/libstd/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -41,6 +41,7 @@ A quick refresher on memory ordering: */ +#![experimental] #![allow(missing_doc)] // This is needed to prevent duplicate lang item definitions. @@ -470,7 +471,7 @@ extern "rust-intrinsic" { /// `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, Hash, Show, TotalEq)] +#[deriving(Eq, TotalEq)] #[cfg(not(test))] pub struct TypeId { t: u64, @@ -482,4 +483,5 @@ impl TypeId { pub fn of() -> TypeId { unsafe { type_id::() } } + pub fn hash(&self) -> u64 { self.t } } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 5d9476f95e30..b76d3b84254a 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -20,3 +20,7 @@ #![no_std] #![feature(globs, macro_rules, managed_boxes)] #![deny(missing_doc)] + +/* Core modules for ownership management */ + +pub mod intrinsics; diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index 38456e195e36..53d6f2fc0d23 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -499,6 +499,7 @@ use str::StrSlice; use str; use slice::{Vector, ImmutableVector}; use slice; +use intrinsics::TypeId; pub use self::num::radix; pub use self::num::Radix; @@ -1241,5 +1242,11 @@ impl Show for *mut T { fn fmt(&self, f: &mut Formatter) -> Result { secret_pointer(self, f) } } +impl Show for TypeId { + fn fmt(&self, f: &mut Formatter) -> Result { + write!(f.buf, "TypeId \\{ {} \\}", self.hash()) + } +} + // If you expected tests to be here, look instead at the run-pass/ifmt.rs test, // it's a lot easier than creating all of the rt::Piece structures here. diff --git a/src/libstd/hash/mod.rs b/src/libstd/hash/mod.rs index 748cf0eeed91..010ddbaa9424 100644 --- a/src/libstd/hash/mod.rs +++ b/src/libstd/hash/mod.rs @@ -64,6 +64,7 @@ #![allow(unused_must_use)] use container::Container; +use intrinsics::TypeId; use io::Writer; use iter::Iterator; use option::{Option, Some, None}; @@ -284,6 +285,13 @@ impl Hash for *mut T { } } +impl Hash for TypeId { + #[inline] + fn hash(&self, state: &mut S) { + self.hash().hash(state) + } +} + ////////////////////////////////////////////////////////////////////////////// #[cfg(test)] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index bf24bf405a04..2c9715429606 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -122,8 +122,8 @@ // Make and rand accessible for benchmarking/testcases #[cfg(test)] extern crate rand; -// we wrap some libc stuff extern crate libc; +extern crate core; // Make std testable by not duplicating lang items. See #2912 #[cfg(test)] extern crate realstd = "std"; @@ -133,6 +133,8 @@ extern crate libc; #[cfg(test)] pub use ty = realstd::ty; #[cfg(test)] pub use owned = realstd::owned; +pub use core::intrinsics; + // Run tests with libgreen instead of libnative. // // FIXME: This egregiously hacks around starting the test runner in a different @@ -255,8 +257,6 @@ pub mod reflect; #[unstable] pub mod unstable; #[experimental] -pub mod intrinsics; -#[experimental] pub mod raw; /* For internal use, not exported */