]> git.lizzy.rs Git - rust.git/blob - library/alloc/tests/lib.rs
Rollup merge of #74859 - mark-i-m:patch-1, r=JohnTitor
[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(split_inclusive)]
17 #![feature(binary_heap_retain)]
18
19 use std::collections::hash_map::DefaultHasher;
20 use std::hash::{Hash, Hasher};
21
22 mod arc;
23 mod binary_heap;
24 mod borrow;
25 mod boxed;
26 mod btree;
27 mod cow_str;
28 mod fmt;
29 mod heap;
30 mod linked_list;
31 mod rc;
32 mod slice;
33 mod str;
34 mod string;
35 mod vec;
36 mod vec_deque;
37
38 fn hash<T: Hash>(t: &T) -> u64 {
39     let mut s = DefaultHasher::new();
40     t.hash(&mut s);
41     s.finish()
42 }
43
44 // FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
45 // See https://github.com/kripken/emscripten-fastcomp/issues/169
46 #[cfg(not(target_os = "emscripten"))]
47 #[test]
48 fn test_boxed_hasher() {
49     let ordinary_hash = hash(&5u32);
50
51     let mut hasher_1 = Box::new(DefaultHasher::new());
52     5u32.hash(&mut hasher_1);
53     assert_eq!(ordinary_hash, hasher_1.finish());
54
55     let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
56     5u32.hash(&mut hasher_2);
57     assert_eq!(ordinary_hash, hasher_2.finish());
58 }