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