Skip to content

Commit ea70456

Browse files
committed
Update tests
1 parent e77de9d commit ea70456

34 files changed

Lines changed: 656 additions & 401 deletions

‎tests/multi-file/static_name_collision/out/unsafe/static_name_collision.rs‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ use std::collections::BTreeMap;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
88
use std::rc::Rc;
9-
pub static mut same_name_different_type_0: i32 = unsafe { 1 };
10-
pub static mut same_name_same_type_1: i32 = unsafe { 5 };
9+
pub static mut same_name_different_type_0: std::cell::LazyCell<i32> =
10+
std::cell::LazyCell::new(|| unsafe { 1 });
11+
pub static mut same_name_same_type_1: std::cell::LazyCell<i32> =
12+
std::cell::LazyCell::new(|| unsafe { 5 });
1113
pub unsafe fn a_foo_2() -> i32 {
12-
return same_name_different_type_0;
14+
return (*std::cell::LazyCell::force_mut(&mut *&raw mut same_name_different_type_0));
1315
}
1416
pub unsafe fn a_bar_3() -> i32 {
15-
return same_name_same_type_1;
17+
return (*std::cell::LazyCell::force_mut(&mut *&raw mut same_name_same_type_1));
1618
}
1719
pub fn main() {
1820
unsafe {
@@ -26,11 +28,13 @@ unsafe fn main_0() -> i32 {
2628
assert!(((((unsafe { b_bar_5() }) == (6)) as i32) != 0));
2729
return 0;
2830
}
29-
pub static mut same_name_different_type_6: f32 = unsafe { 1.0E+0 };
30-
pub static mut same_name_same_type_7: i32 = unsafe { 6 };
31+
pub static mut same_name_different_type_6: std::cell::LazyCell<f32> =
32+
std::cell::LazyCell::new(|| unsafe { 1.0E+0 });
33+
pub static mut same_name_same_type_7: std::cell::LazyCell<i32> =
34+
std::cell::LazyCell::new(|| unsafe { 6 });
3135
pub unsafe fn b_foo_4() -> f32 {
32-
return same_name_different_type_6;
36+
return (*std::cell::LazyCell::force_mut(&mut *&raw mut same_name_different_type_6));
3337
}
3438
pub unsafe fn b_bar_5() -> i32 {
35-
return same_name_same_type_7;
39+
return (*std::cell::LazyCell::force_mut(&mut *&raw mut same_name_same_type_7));
3640
}

‎tests/unit/out/unsafe/addr_of_global.rs‎

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,49 @@ pub struct Inner {
1616
pub struct Outer {
1717
pub p: *mut Inner,
1818
}
19-
pub static mut alpha_0: Inner = unsafe { Inner { value: 1 } };
20-
pub static mut beta_1: Inner = unsafe { Inner { value: 2 } };
21-
pub static mut shared_2: Inner = unsafe { Inner { value: 42 } };
22-
pub static mut items_3: [*mut Inner; 2] = unsafe {
23-
[
24-
(&raw mut alpha_0 as *mut Inner),
25-
(&raw mut beta_1 as *mut Inner),
26-
]
27-
};
28-
pub static mut obj_4: Outer = unsafe {
19+
pub static mut alpha_0: std::cell::LazyCell<Inner> =
20+
std::cell::LazyCell::new(|| unsafe { Inner { value: 1 } });
21+
pub static mut beta_1: std::cell::LazyCell<Inner> =
22+
std::cell::LazyCell::new(|| unsafe { Inner { value: 2 } });
23+
pub static mut shared_2: std::cell::LazyCell<Inner> =
24+
std::cell::LazyCell::new(|| unsafe { Inner { value: 42 } });
25+
pub static mut items_3: std::cell::LazyCell<[*mut Inner; 2]> =
26+
std::cell::LazyCell::new(|| unsafe {
27+
[
28+
(&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut alpha_0)) as *mut Inner),
29+
(&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut beta_1)) as *mut Inner),
30+
]
31+
});
32+
pub static mut obj_4: std::cell::LazyCell<Outer> = std::cell::LazyCell::new(|| unsafe {
2933
Outer {
30-
p: (&raw mut shared_2 as *mut Inner),
34+
p: (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_2)) as *mut Inner),
3135
}
32-
};
36+
});
3337
pub fn main() {
3438
unsafe {
3539
std::process::exit(main_0() as i32);
3640
}
3741
}
3842
unsafe fn main_0() -> i32 {
39-
assert!((((*items_3[(0) as usize]).value) == (1)));
40-
assert!((((*items_3[(1) as usize]).value) == (2)));
41-
assert!((((*obj_4.p).value) == (42)));
42-
static mut cache_5: [*mut Inner; 2] = unsafe {
43-
[
44-
(&raw mut alpha_0 as *mut Inner),
45-
(&raw mut beta_1 as *mut Inner),
46-
]
47-
};;
48-
assert!((((*cache_5[(0) as usize]).value) == (1)));
49-
assert!((((*cache_5[(1) as usize]).value) == (2)));
43+
assert!(
44+
(((*(*std::cell::LazyCell::force_mut(&mut *&raw mut items_3))[(0) as usize]).value) == (1))
45+
);
46+
assert!(
47+
(((*(*std::cell::LazyCell::force_mut(&mut *&raw mut items_3))[(1) as usize]).value) == (2))
48+
);
49+
assert!((((*(*std::cell::LazyCell::force_mut(&mut *&raw mut obj_4)).p).value) == (42)));
50+
static mut cache_5: std::cell::LazyCell<[*mut Inner; 2]> =
51+
std::cell::LazyCell::new(|| unsafe {
52+
[
53+
(&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut alpha_0)) as *mut Inner),
54+
(&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut beta_1)) as *mut Inner),
55+
]
56+
});;
57+
assert!(
58+
(((*(*std::cell::LazyCell::force_mut(&mut *&raw mut cache_5))[(0) as usize]).value) == (1))
59+
);
60+
assert!(
61+
(((*(*std::cell::LazyCell::force_mut(&mut *&raw mut cache_5))[(1) as usize]).value) == (2))
62+
);
5063
return 0;
5164
}

‎tests/unit/out/unsafe/array_const_init.rs‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,36 @@ impl Default for S {
2222
}
2323
}
2424
}
25-
pub static mut s_0: S = unsafe {
25+
pub static mut s_0: std::cell::LazyCell<S> = std::cell::LazyCell::new(|| unsafe {
2626
S {
2727
head: 5,
2828
tail: [0; 3],
2929
buf: [0; 4],
3030
}
31-
};
31+
});
3232
pub fn main() {
3333
unsafe {
3434
std::process::exit(main_0() as i32);
3535
}
3636
}
3737
unsafe fn main_0() -> i32 {
38-
assert!(((((s_0.head) == (5)) as i32) != 0));
38+
assert!((((((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)).head) == (5)) as i32) != 0));
3939
let mut i: i32 = 0;
4040
'loop_: while ((((i) < (3)) as i32) != 0) {
41-
assert!(((((s_0.tail[(i) as usize]) == (0)) as i32) != 0));
41+
assert!(
42+
(((((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)).tail[(i) as usize]) == (0))
43+
as i32)
44+
!= 0)
45+
);
4246
i.postfix_inc();
4347
}
4448
let mut i: i32 = 0;
4549
'loop_: while ((((i) < (4)) as i32) != 0) {
46-
assert!(((((s_0.buf[(i) as usize] as i32) == (0)) as i32) != 0));
50+
assert!(
51+
(((((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)).buf[(i) as usize] as i32)
52+
== (0)) as i32)
53+
!= 0)
54+
);
4755
i.postfix_inc();
4856
}
4957
return 0;

‎tests/unit/out/unsafe/bool_condition_logical.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ pub type Code = u32;
1010
pub const Code_CODE_OK: Code = 0;
1111
pub const Code_CODE_ERR: Code = 1;
1212
pub const Code_CODE_FATAL: Code = 2;
13-
pub static mut side_effect_0: i32 = unsafe { 0 };
13+
pub static mut side_effect_0: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 0 });
1414
pub unsafe fn observe_1(mut v: i32) -> i32 {
15-
side_effect_0.prefix_inc();
15+
(*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)).prefix_inc();
1616
return v;
1717
}
1818
pub unsafe fn returns_one_2() -> i32 {
@@ -49,15 +49,15 @@ unsafe fn main_0() -> i32 {
4949
if (((n != 0) && (u != 0)) && (!(p).is_null())) && ((code as i32) == (Code_CODE_OK as i32)) {
5050
assert!(true);
5151
}
52-
side_effect_0 = 0;
52+
(*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) = 0;
5353
if (zero != 0) && ((unsafe { observe_1(1) }) != 0) {
5454
assert!(false);
5555
}
56-
assert!(((side_effect_0) == (0)));
56+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) == (0)));
5757
if (n != 0) || ((unsafe { observe_1(1) }) != 0) {
5858
assert!(true);
5959
}
60-
assert!(((side_effect_0) == (0)));
60+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) == (0)));
6161
let mut x: i32 = 5;
6262
let mut y: i32 = 3;
6363
let mut flags: u32 = 2_u32;

‎tests/unit/out/unsafe/bool_condition_logical_c.rs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ pub type Code = u32;
1010
pub const Code_CODE_OK: Code = 0;
1111
pub const Code_CODE_ERR: Code = 1;
1212
pub const Code_CODE_FATAL: Code = 2;
13-
pub static mut side_effect_0: i32 = unsafe { 0 };
13+
pub static mut side_effect_0: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 0 });
1414
pub unsafe fn observe_1(mut v: i32) -> i32 {
15-
side_effect_0.prefix_inc();
15+
(*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)).prefix_inc();
1616
return v;
1717
}
1818
pub unsafe fn returns_one_2() -> i32 {
@@ -52,15 +52,19 @@ unsafe fn main_0() -> i32 {
5252
{
5353
assert!((1 != 0));
5454
}
55-
side_effect_0 = 0;
55+
(*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) = 0;
5656
if ((((zero != 0) && ((unsafe { observe_1(1) }) != 0)) as i32) != 0) {
5757
assert!((0 != 0));
5858
}
59-
assert!(((((side_effect_0) == (0)) as i32) != 0));
59+
assert!(
60+
((((*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) == (0)) as i32) != 0)
61+
);
6062
if ((((n != 0) || ((unsafe { observe_1(1) }) != 0)) as i32) != 0) {
6163
assert!((1 != 0));
6264
}
63-
assert!(((((side_effect_0) == (0)) as i32) != 0));
65+
assert!(
66+
((((*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) == (0)) as i32) != 0)
67+
);
6468
let mut x: i32 = 5;
6569
let mut y: i32 = 3;
6670
let mut flags: u32 = 2_u32;

‎tests/unit/out/unsafe/constructor.rs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::BTreeMap;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
88
use std::rc::Rc;
9-
pub static mut total_0: i32 = unsafe { 0 };
9+
pub static mut total_0: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 0 });
1010
#[repr(C)]
1111
#[derive(Clone, Default)]
1212
pub struct S {
@@ -22,12 +22,14 @@ impl S {
2222
pub unsafe fn S(mut init: i32) -> Self {
2323
let mut this = Self { v: init };
2424
(unsafe { S::mut_method(&mut this) });
25-
total_0 += (unsafe { S::const_method(&mut this) });
25+
(*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) +=
26+
(unsafe { S::const_method(&mut this) });
2627
this
2728
}
2829
pub unsafe fn destructor(&mut self) {
2930
(unsafe { S::mut_method(self) });
30-
total_0 += (unsafe { S::const_method(self) });
31+
(*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) +=
32+
(unsafe { S::const_method(self) });
3133
}
3234
}
3335
pub fn main() {
@@ -40,8 +42,8 @@ unsafe fn main_0() -> i32 {
4042
let mut s: S = S::S({ 3 });
4143
let _dtor_s = ScopedDestructorUnsafe::new(&raw mut s, S::destructor);
4244
assert!(((s.v) == (4)));
43-
assert!(((total_0) == (8)));
45+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (8)));
4446
}
45-
assert!(((total_0) == (18)));
47+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (18)));
4648
return 0;
4749
}

‎tests/unit/out/unsafe/copy_assign.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::BTreeMap;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
88
use std::rc::Rc;
9-
pub static mut assigns_0: i32 = unsafe { 0 };
9+
pub static mut assigns_0: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 0 });
1010
#[repr(C)]
1111
#[derive(Default)]
1212
pub struct Partial {
@@ -30,7 +30,7 @@ impl Partial {
3030
return &mut (*(self as *mut Partial)) as *mut Partial;
3131
}
3232
self.v = (*o).v;
33-
assigns_0.prefix_inc();
33+
(*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)).prefix_inc();
3434
return &mut (*(self as *mut Partial)) as *mut Partial;
3535
}
3636
}
@@ -114,7 +114,7 @@ unsafe fn main_0() -> i32 {
114114
let mut c: Partial = Partial::Partial({ 3 }, { 300 });
115115
(unsafe { Partial::operator_assign(&mut a, &b as *const Partial) });
116116
assert!(((a.v) == (2)) && ((a.keep) == (100)));
117-
assert!(((assigns_0) == (1)));
117+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (1)));
118118
(unsafe {
119119
Partial::operator_assign(
120120
&mut c,
@@ -123,18 +123,18 @@ unsafe fn main_0() -> i32 {
123123
)
124124
});
125125
assert!(((c.v) == (2)) && ((c.keep) == (300)));
126-
assert!(((assigns_0) == (3)));
126+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3)));
127127
(unsafe {
128128
let _o: *const Partial = &a as *const Partial;
129129
Partial::operator_assign(&mut a, _o)
130130
});
131-
assert!(((assigns_0) == (3)));
131+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3)));
132132
(unsafe {
133133
let mut _o: Partial = Partial::Partial({ 9 }, { 900 });
134134
Partial::operator_assign(&mut a, &mut _o)
135135
});
136136
assert!(((a.v) == (9)) && ((a.keep) == (100)));
137-
assert!(((assigns_0) == (4)));
137+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (4)));
138138
let ra: *mut Partial = &mut a as *mut Partial;
139139
(unsafe {
140140
let _o: *const Partial = &c as *const Partial;
@@ -147,7 +147,7 @@ unsafe fn main_0() -> i32 {
147147
Partial::operator_assign(&mut (*pa), _o)
148148
});
149149
assert!(((a.v) == (2)));
150-
assert!(((assigns_0) == (6)));
150+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (6)));
151151
let mut h: Holder = Holder {
152152
p: Partial::Partial({ 4 }, { 40 }),
153153
arr: [
@@ -159,7 +159,7 @@ unsafe fn main_0() -> i32 {
159159
(unsafe { Partial::operator_assign(&mut h.arr[(1) as usize], &c as *const Partial) });
160160
assert!(((h.p.v) == (2)) && ((h.p.keep) == (40)));
161161
assert!(((h.arr[(1) as usize].v) == (2)) && ((h.arr[(1) as usize].keep) == (60)));
162-
assert!(((assigns_0) == (8)));
162+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (8)));
163163
let mut n: NonConstAssign = NonConstAssign::NonConstAssign();
164164
let mut n1: NonConstAssign = NonConstAssign::NonConstAssign();
165165
let mut n2: NonConstAssign = NonConstAssign::NonConstAssign();

‎tests/unit/out/unsafe/copy_ctor.rs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::BTreeMap;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
88
use std::rc::Rc;
9-
pub static mut copies_0: i32 = unsafe { 0 };
9+
pub static mut copies_0: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 0 });
1010
#[repr(C)]
1111
#[derive(Default)]
1212
pub struct Counted {
@@ -19,7 +19,7 @@ impl Counted {
1919
}
2020
pub unsafe fn Counted_pconstCounted(o: *const Counted) -> Self {
2121
let mut this = Self { v: (*o).v };
22-
copies_0.prefix_inc();
22+
(*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc();
2323
this
2424
}
2525
}
@@ -92,23 +92,23 @@ unsafe fn main_0() -> i32 {
9292
let mut b: Counted = Counted::Counted_pconstCounted({ &a as *const Counted });
9393
let mut c: Counted = Counted::Counted_pconstCounted({ &a as *const Counted });
9494
let mut d: Counted = Counted::Counted_pconstCounted({ &a as *const Counted });
95-
assert!(((copies_0) == (3)));
95+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (3)));
9696
assert!((((b.v) == (1)) && ((c.v) == (1))) && ((d.v) == (1)));
9797
assert!(
9898
((unsafe { by_value_1(Counted::Counted_pconstCounted({ &a as *const Counted },),) })
9999
== (1))
100100
);
101-
assert!(((copies_0) == (4)));
101+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (4)));
102102
let mut e: Counted = (unsafe { make_2(5) });
103103
assert!(((e.v) == (5)));
104-
assert!(((copies_0) == (5)));
104+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5)));
105105
let mut f: Counted = Counted::Counted({ 6 });
106106
assert!(((f.v) == (6)));
107-
assert!(((copies_0) == (5)));
107+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5)));
108108
let g: Counted = Counted::Counted({ 7 });
109109
let mut h: Counted = Counted::Counted_pconstCounted({ &g as *const Counted });
110110
assert!(((h.v) == (7)));
111-
assert!(((copies_0) == (6)));
111+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (6)));
112112
let mut hold: Holder = Holder {
113113
c: Counted::Counted({ 8 }),
114114
arr: [Counted::Counted({ 9 }), Counted::Counted({ 10 })],
@@ -118,14 +118,14 @@ unsafe fn main_0() -> i32 {
118118
(((hold2.c.v) == (8)) && ((hold2.arr[(0) as usize].v) == (9)))
119119
&& ((hold2.arr[(1) as usize].v) == (10))
120120
);
121-
assert!(((copies_0) == (9)));
121+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (9)));
122122
let mut vec_: Vec<Counted> = Vec::new();
123123
{
124124
let a0_clone = a.clone();
125125
vec_.push(a0_clone)
126126
};
127127
assert!(((vec_[(0_usize)].v) == (1)));
128-
assert!(((copies_0) == (10)));
128+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (10)));
129129
let mut n: NonConst = NonConst::NonConst();
130130
let mut n1: NonConst = NonConst::NonConst_pmutNonConst({ &mut n as *mut NonConst });
131131
let cn: NonConst = NonConst::NonConst();

0 commit comments

Comments
 (0)