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