diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-04-30 20:04:56 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-07 08:12:48 -0700 |
| commit | 5b75e44fb01f0eda10ce8d8df92b80945d894768 (patch) | |
| tree | 5d8a2300e8eacc5afa7d1f98a562c125c5189f92 /src | |
| parent | 836d4b96a91cd6a36228d757004655e26e3f2c46 (diff) | |
| download | rust-5b75e44fb01f0eda10ce8d8df92b80945d894768.tar.gz rust-5b75e44fb01f0eda10ce8d8df92b80945d894768.zip | |
core: Inherit the intrinsics module
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/intrinsics.rs (renamed from src/libstd/intrinsics.rs) | 4 | ||||
| -rw-r--r-- | src/libcore/lib.rs | 4 | ||||
| -rw-r--r-- | src/libstd/fmt/mod.rs | 7 | ||||
| -rw-r--r-- | src/libstd/hash/mod.rs | 8 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 6 |
5 files changed, 25 insertions, 4 deletions
diff --git a/src/libstd/intrinsics.rs b/src/libcore/intrinsics.rs index c2d39ad990a..770433c4521 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<T: 'static>() -> TypeId { unsafe { type_id::<T>() } } + pub fn hash(&self) -> u64 { self.t } } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 5d9476f95e3..b76d3b84254 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 38456e195e3..53d6f2fc0d2 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<T> 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 748cf0eeed9..010ddbaa942 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<S: Writer, T> Hash<S> for *mut T { } } +impl<S: Writer> Hash<S> 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 bf24bf405a0..2c971542960 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 */ |
