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