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