]> git.lizzy.rs Git - rust.git/blob - library/alloc/tests/lib.rs
Rollup merge of #92231 - ehuss:update-books, r=ehuss
[rust.git] / library / alloc / tests / lib.rs
1 #![feature(allocator_api)]
2 #![feature(assert_matches)]
3 #![feature(box_syntax)]
4 #![feature(cow_is_borrowed)]
5 #![feature(const_cow_is_borrowed)]
6 #![feature(drain_filter)]
7 #![feature(exact_size_is_empty)]
8 #![feature(new_uninit)]
9 #![feature(pattern)]
10 #![feature(trusted_len)]
11 #![feature(try_reserve_kind)]
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(binary_heap_retain)]
18 #![feature(binary_heap_as_slice)]
19 #![feature(inplace_iteration)]
20 #![feature(iter_advance_by)]
21 #![feature(slice_group_by)]
22 #![feature(slice_partition_dedup)]
23 #![feature(vec_spare_capacity)]
24 #![feature(string_remove_matches)]
25 #![feature(const_btree_new)]
26 #![feature(const_default_impls)]
27 #![feature(const_trait_impl)]
28 #![feature(const_str_from_utf8)]
29
30 use std::collections::hash_map::DefaultHasher;
31 use std::hash::{Hash, Hasher};
32
33 mod arc;
34 mod binary_heap;
35 mod borrow;
36 mod boxed;
37 mod btree_set_hash;
38 mod const_fns;
39 mod cow_str;
40 mod fmt;
41 mod heap;
42 mod linked_list;
43 mod rc;
44 mod slice;
45 mod str;
46 mod string;
47 mod vec;
48 mod vec_deque;
49
50 fn hash<T: Hash>(t: &T) -> u64 {
51     let mut s = DefaultHasher::new();
52     t.hash(&mut s);
53     s.finish()
54 }
55
56 // FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
57 // See https://github.com/kripken/emscripten-fastcomp/issues/169
58 #[cfg(not(target_os = "emscripten"))]
59 #[test]
60 fn test_boxed_hasher() {
61     let ordinary_hash = hash(&5u32);
62
63     let mut hasher_1 = Box::new(DefaultHasher::new());
64     5u32.hash(&mut hasher_1);
65     assert_eq!(ordinary_hash, hasher_1.finish());
66
67     let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
68     5u32.hash(&mut hasher_2);
69     assert_eq!(ordinary_hash, hasher_2.finish());
70 }