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