File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,38 @@ use core::cell::*;
2
2
use core:: default:: Default ;
3
3
use std:: mem:: drop;
4
4
5
+ #[ test]
6
+ fn smoketest_unsafe_cell ( ) {
7
+ let mut x = UnsafeCell :: new ( 10 ) ;
8
+ let ref_mut = & mut x;
9
+ unsafe {
10
+ // The asserts are repeated in order to ensure that `get()`
11
+ // is non-mutating.
12
+ assert_eq ! ( * ref_mut. get( ) , 10 ) ;
13
+ assert_eq ! ( * ref_mut. get( ) , 10 ) ;
14
+ * ref_mut. get_mut ( ) += 5 ;
15
+ assert_eq ! ( * ref_mut. get( ) , 15 ) ;
16
+ assert_eq ! ( * ref_mut. get( ) , 15 ) ;
17
+ assert_eq ! ( x. into_inner( ) , 15 ) ;
18
+ }
19
+ }
20
+
21
+ #[ test]
22
+ fn unsafe_cell_raw_get ( ) {
23
+ let x = UnsafeCell :: new ( 10 ) ;
24
+ let ptr = & x as * const UnsafeCell < i32 > ;
25
+ unsafe {
26
+ // The asserts are repeated in order to ensure that `raw_get()`
27
+ // is non-mutating.
28
+ assert_eq ! ( * UnsafeCell :: raw_get( ptr) , 10 ) ;
29
+ assert_eq ! ( * UnsafeCell :: raw_get( ptr) , 10 ) ;
30
+ * UnsafeCell :: raw_get ( ptr) += 5 ;
31
+ assert_eq ! ( * UnsafeCell :: raw_get( ptr) , 15 ) ;
32
+ assert_eq ! ( * UnsafeCell :: raw_get( ptr) , 15 ) ;
33
+ assert_eq ! ( x. into_inner( ) , 15 ) ;
34
+ }
35
+ }
36
+
5
37
#[ test]
6
38
fn smoketest_cell ( ) {
7
39
let x = Cell :: new ( 10 ) ;
You can’t perform that action at this time.
0 commit comments