]> git.lizzy.rs Git - rust.git/blob - src/liballoc/tests/lib.rs
Rollup merge of #68150 - tillarnold:master, r=cramertj
[rust.git] / src / liballoc / tests / lib.rs
1 #![feature(allocator_api)]
2 #![feature(box_syntax)]
3 #![feature(drain_filter)]
4 #![feature(exact_size_is_empty)]
5 #![feature(map_first_last)]
6 #![feature(new_uninit)]
7 #![feature(pattern)]
8 #![feature(trusted_len)]
9 #![feature(try_reserve)]
10 #![feature(unboxed_closures)]
11 #![feature(associated_type_bounds)]
12 #![feature(binary_heap_into_iter_sorted)]
13 #![feature(binary_heap_drain_sorted)]
14 #![feature(vec_remove_item)]
15
16 use std::collections::hash_map::DefaultHasher;
17 use std::hash::{Hash, Hasher};
18
19 mod arc;
20 mod binary_heap;
21 mod boxed;
22 mod btree;
23 mod cow_str;
24 mod fmt;
25 mod heap;
26 mod linked_list;
27 mod rc;
28 mod slice;
29 mod str;
30 mod string;
31 mod vec;
32 mod vec_deque;
33
34 fn hash<T: Hash>(t: &T) -> u64 {
35     let mut s = DefaultHasher::new();
36     t.hash(&mut s);
37     s.finish()
38 }
39
40 // FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
41 // See https://github.com/kripken/emscripten-fastcomp/issues/169
42 #[cfg(not(target_os = "emscripten"))]
43 #[test]
44 fn test_boxed_hasher() {
45     let ordinary_hash = hash(&5u32);
46
47     let mut hasher_1 = Box::new(DefaultHasher::new());
48     5u32.hash(&mut hasher_1);
49     assert_eq!(ordinary_hash, hasher_1.finish());
50
51     let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
52     5u32.hash(&mut hasher_2);
53     assert_eq!(ordinary_hash, hasher_2.finish());
54 }