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