]> git.lizzy.rs Git - rust.git/blob - library/alloc/tests/lib.rs
Rollup merge of #94467 - ibraheemdev:master, r=pnkfelix
[rust.git] / library / alloc / tests / lib.rs
1 #![feature(allocator_api)]
2 #![feature(alloc_layout_extra)]
3 #![feature(assert_matches)]
4 #![feature(box_syntax)]
5 #![feature(cow_is_borrowed)]
6 #![feature(const_box)]
7 #![feature(const_convert)]
8 #![feature(const_cow_is_borrowed)]
9 #![feature(const_heap)]
10 #![feature(const_mut_refs)]
11 #![feature(const_nonnull_slice_from_raw_parts)]
12 #![feature(const_ptr_write)]
13 #![feature(const_try)]
14 #![feature(core_intrinsics)]
15 #![feature(drain_filter)]
16 #![feature(exact_size_is_empty)]
17 #![feature(new_uninit)]
18 #![feature(pattern)]
19 #![feature(trusted_len)]
20 #![feature(try_reserve_kind)]
21 #![feature(unboxed_closures)]
22 #![feature(associated_type_bounds)]
23 #![feature(binary_heap_into_iter_sorted)]
24 #![feature(binary_heap_drain_sorted)]
25 #![feature(slice_ptr_get)]
26 #![feature(binary_heap_retain)]
27 #![feature(binary_heap_as_slice)]
28 #![feature(inplace_iteration)]
29 #![feature(iter_advance_by)]
30 #![feature(iter_next_chunk)]
31 #![feature(round_char_boundary)]
32 #![feature(slice_group_by)]
33 #![feature(slice_partition_dedup)]
34 #![feature(string_remove_matches)]
35 #![feature(const_btree_new)]
36 #![feature(const_default_impls)]
37 #![feature(const_trait_impl)]
38 #![feature(const_str_from_utf8)]
39 #![feature(nonnull_slice_from_raw_parts)]
40 #![feature(panic_update_hook)]
41 #![feature(pointer_is_aligned)]
42 #![feature(slice_flatten)]
43 #![feature(thin_box)]
44 #![feature(bench_black_box)]
45 #![feature(strict_provenance)]
46 #![feature(once_cell)]
47 #![feature(drain_keep_rest)]
48
49 use std::collections::hash_map::DefaultHasher;
50 use std::hash::{Hash, Hasher};
51
52 mod arc;
53 mod borrow;
54 mod boxed;
55 mod btree_set_hash;
56 mod c_str;
57 mod const_fns;
58 mod cow_str;
59 mod fmt;
60 mod heap;
61 mod linked_list;
62 mod rc;
63 mod slice;
64 mod str;
65 mod string;
66 mod thin_box;
67 mod vec;
68 mod vec_deque;
69
70 fn hash<T: Hash>(t: &T) -> u64 {
71     let mut s = DefaultHasher::new();
72     t.hash(&mut s);
73     s.finish()
74 }
75
76 // FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
77 // See https://github.com/kripken/emscripten-fastcomp/issues/169
78 #[cfg(not(target_os = "emscripten"))]
79 #[test]
80 fn test_boxed_hasher() {
81     let ordinary_hash = hash(&5u32);
82
83     let mut hasher_1 = Box::new(DefaultHasher::new());
84     5u32.hash(&mut hasher_1);
85     assert_eq!(ordinary_hash, hasher_1.finish());
86
87     let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
88     5u32.hash(&mut hasher_2);
89     assert_eq!(ordinary_hash, hasher_2.finish());
90 }