1
1
use super :: getrandom_impl;
2
- use core:: mem:: { self , MaybeUninit } ;
3
2
4
3
#[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
5
4
use wasm_bindgen_test:: wasm_bindgen_test as test;
@@ -10,16 +9,16 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
10
9
#[ test]
11
10
fn test_zero ( ) {
12
11
// Test that APIs are happy with zero-length requests
13
- getrandom_impl ( unsafe { slice_as_uninit_mut ( & mut [ 0u8 ; 0 ] ) } ) . unwrap ( ) ;
12
+ getrandom_impl ( & mut [ 0u8 ; 0 ] ) . unwrap ( ) ;
14
13
}
15
14
16
15
#[ test]
17
16
fn test_diff ( ) {
18
17
let mut v1 = [ 0u8 ; 1000 ] ;
19
- getrandom_impl ( unsafe { slice_as_uninit_mut ( & mut v1) } ) . unwrap ( ) ;
18
+ getrandom_impl ( & mut v1) . unwrap ( ) ;
20
19
21
20
let mut v2 = [ 0u8 ; 1000 ] ;
22
- getrandom_impl ( unsafe { slice_as_uninit_mut ( & mut v2) } ) . unwrap ( ) ;
21
+ getrandom_impl ( & mut v2) . unwrap ( ) ;
23
22
24
23
let mut n_diff_bits = 0 ;
25
24
for i in 0 ..v1. len ( ) {
@@ -33,7 +32,7 @@ fn test_diff() {
33
32
#[ test]
34
33
fn test_huge ( ) {
35
34
let mut huge = [ 0u8 ; 100_000 ] ;
36
- getrandom_impl ( unsafe { slice_as_uninit_mut ( & mut huge) } ) . unwrap ( ) ;
35
+ getrandom_impl ( & mut huge) . unwrap ( ) ;
37
36
}
38
37
39
38
// On WASM, the thread API always fails/panics
@@ -52,9 +51,9 @@ fn test_multithreading() {
52
51
// wait until all the tasks are ready to go.
53
52
rx. recv ( ) . unwrap ( ) ;
54
53
let mut v = [ 0u8 ; 1000 ] ;
55
- let y = unsafe { slice_as_uninit_mut ( & mut v ) } ;
54
+
56
55
for _ in 0 ..100 {
57
- getrandom_impl ( y ) . unwrap ( ) ;
56
+ getrandom_impl ( & mut v ) . unwrap ( ) ;
58
57
thread:: yield_now ( ) ;
59
58
}
60
59
} ) ;
@@ -65,9 +64,3 @@ fn test_multithreading() {
65
64
tx. send ( ( ) ) . unwrap ( ) ;
66
65
}
67
66
}
68
-
69
- #[ inline( always) ]
70
- unsafe fn slice_as_uninit_mut < T > ( slice : & mut [ T ] ) -> & mut [ MaybeUninit < T > ] {
71
- // SAFETY: `MaybeUninit<T>` is guaranteed to be layout-compatible with `T`.
72
- mem:: transmute ( slice)
73
- }
0 commit comments