about summary refs log tree commit diff
path: root/src/liballoc/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-09-12 21:39:08 +0000
committerbors <bors@rust-lang.org>2017-09-12 21:39:08 +0000
commit2fdccaffe632e316c43224d0fae6fba903333aa3 (patch)
tree8c4b986ac2c0e210e943e60146ada289396b6a8a /src/liballoc/tests
parentdd08c30703d052205a68ae34331eea464178cd99 (diff)
parent143e2dcd5ce3a7ba5953378cde0f2850850d6e9f (diff)
downloadrust-2fdccaffe632e316c43224d0fae6fba903333aa3.tar.gz
rust-2fdccaffe632e316c43224d0fae6fba903333aa3.zip
Auto merge of #44015 - kennytm:hasher, r=alexcrichton
 impl Hasher for {&mut Hasher, Box<Hasher>}

**Rationale:** The `Hash` trait has `fn hash<H: Hasher>(&self, state: &mut H)`, which can only accept a `Sized` hasher, even if the `Hasher` trait is object-safe. We cannot retroactively add the `?Sized` bound without breaking stability, thus implementing `Hasher` to a trait object reference is the next best solution.

**Warning:** These `impl` are insta-stable, and should need an FCP. I don't think a full RFC is necessary.
Diffstat (limited to 'src/liballoc/tests')
-rw-r--r--src/liballoc/tests/lib.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs
index 8f3e71ef794..c5beb63d12e 100644
--- a/src/liballoc/tests/lib.rs
+++ b/src/liballoc/tests/lib.rs
@@ -50,3 +50,19 @@ fn hash<T: Hash>(t: &T) -> u64 {
     t.hash(&mut s);
     s.finish()
 }
+
+// FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
+// See https://github.com/kripken/emscripten-fastcomp/issues/169
+#[cfg(not(target_os = "emscripten"))]
+#[test]
+fn test_boxed_hasher() {
+    let ordinary_hash = hash(&5u32);
+
+    let mut hasher_1 = Box::new(DefaultHasher::new());
+    5u32.hash(&mut hasher_1);
+    assert_eq!(ordinary_hash, hasher_1.finish());
+
+    let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<Hasher>;
+    5u32.hash(&mut hasher_2);
+    assert_eq!(ordinary_hash, hasher_2.finish());
+}