]> git.proxmox.com Git - rustc.git/blob - library/alloc/tests/lib.rs
New upstream version 1.61.0+dfsg1
[rustc.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_intrinsics)]
16 #![feature(drain_filter)]
17 #![feature(exact_size_is_empty)]
18 #![feature(new_uninit)]
19 #![feature(pattern)]
20 #![feature(trusted_len)]
21 #![feature(try_reserve_kind)]
22 #![feature(unboxed_closures)]
23 #![feature(associated_type_bounds)]
24 #![feature(binary_heap_into_iter_sorted)]
25 #![feature(binary_heap_drain_sorted)]
26 #![feature(slice_ptr_get)]
27 #![feature(binary_heap_retain)]
28 #![feature(binary_heap_as_slice)]
29 #![feature(inplace_iteration)]
30 #![feature(iter_advance_by)]
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
42 use std::collections::hash_map::DefaultHasher;
43 use std::hash::{Hash, Hasher};
44
45 mod arc;
46 mod binary_heap;
47 mod borrow;
48 mod boxed;
49 mod btree_set_hash;
50 mod const_fns;
51 mod cow_str;
52 mod fmt;
53 mod heap;
54 mod linked_list;
55 mod rc;
56 mod slice;
57 mod str;
58 mod string;
59 mod vec;
60 mod vec_deque;
61
62 fn hash<T: Hash>(t: &T) -> u64 {
63 let mut s = DefaultHasher::new();
64 t.hash(&mut s);
65 s.finish()
66 }
67
68 // FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
69 // See https://github.com/kripken/emscripten-fastcomp/issues/169
70 #[cfg(not(target_os = "emscripten"))]
71 #[test]
72 fn test_boxed_hasher() {
73 let ordinary_hash = hash(&5u32);
74
75 let mut hasher_1 = Box::new(DefaultHasher::new());
76 5u32.hash(&mut hasher_1);
77 assert_eq!(ordinary_hash, hasher_1.finish());
78
79 let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
80 5u32.hash(&mut hasher_2);
81 assert_eq!(ordinary_hash, hasher_2.finish());
82 }