core: Inherit the intrinsics module

This commit is contained in:
Alex Crichton 2014-04-30 20:04:56 -07:00
parent 836d4b96a9
commit 5b75e44fb0
5 changed files with 25 additions and 4 deletions

View File

@ -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 }
}

View File

@ -20,3 +20,7 @@
#![no_std]
#![feature(globs, macro_rules, managed_boxes)]
#![deny(missing_doc)]
/* Core modules for ownership management */
pub mod intrinsics;

View File

@ -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.

View File

@ -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)]

View File

@ -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 */