From 24a8ef63ff786dd702d428f73fd64aac2a828f19 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 12 Dec 2014 18:43:07 -0800 Subject: Move hash module from collections to core --- src/liballoc/boxed.rs | 9 +++++++++ src/liballoc/lib.rs | 2 +- src/liballoc/rc.rs | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src/liballoc') diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index b0ba20b0133..c6afeb063fb 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -15,6 +15,7 @@ use core::clone::Clone; use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering}; use core::default::Default; use core::fmt; +use core::hash::{mod, Hash}; use core::kinds::Sized; use core::mem; use core::option::Option; @@ -93,6 +94,14 @@ impl Ord for Box { } impl Eq for Box {} +impl> Hash for Box { + #[inline] + fn hash(&self, state: &mut S) { + (**self).hash(state); + } +} + + /// Extension methods for an owning `Any` trait object. #[unstable = "post-DST and coherence changes, this will not be a trait but \ rather a direct `impl` on `Box`"] diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 0b27fbd4404..61b5d43d1cb 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -64,7 +64,7 @@ html_root_url = "http://doc.rust-lang.org/nightly/")] #![no_std] -#![feature(lang_items, phase, unsafe_destructor)] +#![feature(lang_items, phase, unsafe_destructor, default_type_params)] #[phase(plugin, link)] extern crate core; diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 217c898e661..7af816f2e09 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -147,6 +147,7 @@ use core::clone::Clone; use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering}; use core::default::Default; use core::fmt; +use core::hash::{mod, Hash}; use core::kinds::marker; use core::mem::{transmute, min_align_of, size_of, forget}; use core::ops::{Deref, Drop}; @@ -594,6 +595,14 @@ impl Ord for Rc { fn cmp(&self, other: &Rc) -> Ordering { (**self).cmp(&**other) } } +// FIXME (#18248) Make `T` `Sized?` +impl> Hash for Rc { + #[inline] + fn hash(&self, state: &mut S) { + (**self).hash(state); + } +} + #[experimental = "Show is experimental."] impl fmt::Show for Rc { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { -- cgit 1.4.1-3-g733a5