Skip to content

Commit fdbfab3

Browse files
committed
Update tests
1 parent 04a9c59 commit fdbfab3

15 files changed

Lines changed: 200 additions & 190 deletions

tests/unit/out/unsafe/addr_of_global.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ pub struct Inner {
1616
pub struct Outer {
1717
pub p: *mut Inner,
1818
}
19-
pub static mut alpha: Inner = Inner { value: 1 };
20-
pub static mut beta: Inner = Inner { value: 2 };
21-
pub static mut shared: Inner = Inner { value: 42 };
22-
pub static mut items: [*mut Inner; 2] = [
23-
(&raw mut alpha as *mut Inner),
24-
(&raw mut beta as *mut Inner),
25-
];
26-
pub static mut obj: Outer = Outer {
27-
p: (&raw mut shared as *mut Inner),
19+
pub static mut alpha: Inner = unsafe { Inner { value: 1 } };
20+
pub static mut beta: Inner = unsafe { Inner { value: 2 } };
21+
pub static mut shared: Inner = unsafe { Inner { value: 42 } };
22+
pub static mut items: [*mut Inner; 2] = unsafe {
23+
[
24+
(&raw mut alpha as *mut Inner),
25+
(&raw mut beta as *mut Inner),
26+
]
27+
};
28+
pub static mut obj: Outer = unsafe {
29+
Outer {
30+
p: (&raw mut shared as *mut Inner),
31+
}
2832
};
2933
pub fn main() {
3034
unsafe {
@@ -35,10 +39,12 @@ unsafe fn main_0() -> i32 {
3539
assert!((((*items[(0) as usize]).value) == (1)));
3640
assert!((((*items[(1) as usize]).value) == (2)));
3741
assert!((((*obj.p).value) == (42)));
38-
static mut cache: [*mut Inner; 2] = [
39-
(&raw mut alpha as *mut Inner),
40-
(&raw mut beta as *mut Inner),
41-
];;
42+
static mut cache: [*mut Inner; 2] = unsafe {
43+
[
44+
(&raw mut alpha as *mut Inner),
45+
(&raw mut beta as *mut Inner),
46+
]
47+
};;
4248
assert!((((*cache[(0) as usize]).value) == (1)));
4349
assert!((((*cache[(1) as usize]).value) == (2)));
4450
return 0;

tests/unit/out/unsafe/bool_condition_logical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl From<i32> for Code {
2323
}
2424
}
2525
}
26-
pub static mut side_effect: i32 = 0;
26+
pub static mut side_effect: i32 = unsafe { 0 };
2727
pub unsafe fn observe_0(mut v: i32) -> i32 {
2828
side_effect.prefix_inc();
2929
return v;

tests/unit/out/unsafe/bool_condition_logical_c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl From<i32> for Code {
2323
}
2424
}
2525
}
26-
pub static mut side_effect: i32 = 0;
26+
pub static mut side_effect: i32 = unsafe { 0 };
2727
pub unsafe fn observe_0(mut v: i32) -> i32 {
2828
side_effect.prefix_inc();
2929
return v;

tests/unit/out/unsafe/default_in_statics.rs

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -58,49 +58,9 @@ impl Default for Foo {
5858
}
5959
}
6060
}
61-
pub static mut static_fn: Option<unsafe fn(i32) -> i32> = None;
62-
pub static mut static_outer: Outer = Outer {
63-
p1: std::ptr::null_mut(),
64-
p2: std::ptr::null(),
65-
arr: [std::ptr::null_mut(); 3],
66-
cp: std::ptr::null(),
67-
pp: std::ptr::null_mut(),
68-
inner: Inner {
69-
v: 0_i32,
70-
name: std::ptr::null(),
71-
},
72-
x: 0_i32,
73-
fn_: None,
74-
};
75-
pub static mut static_inner_array: [Inner; 2] = [Inner {
76-
v: 0_i32,
77-
name: std::ptr::null(),
78-
}; 2];
79-
pub static mut static_foo: Foo = Foo {
80-
s1: b"hello\0".as_ptr(),
81-
s2: std::ptr::null(),
82-
fn1: None,
83-
fn2: None,
84-
n: 42,
85-
};
86-
pub static mut static_foo_array: [Foo; 2] = [
87-
Foo {
88-
s1: b"first\0".as_ptr(),
89-
s2: std::ptr::null(),
90-
fn1: None,
91-
fn2: None,
92-
n: 1,
93-
},
94-
Foo {
95-
s1: b"second\0".as_ptr(),
96-
s2: std::ptr::null(),
97-
fn1: None,
98-
fn2: None,
99-
n: 2,
100-
},
101-
];
102-
pub unsafe fn check_local_static_0() {
103-
static mut local_outer: Outer = Outer {
61+
pub static mut static_fn: Option<unsafe fn(i32) -> i32> = unsafe { None };
62+
pub static mut static_outer: Outer = unsafe {
63+
Outer {
10464
p1: std::ptr::null_mut(),
10565
p2: std::ptr::null(),
10666
arr: [std::ptr::null_mut(); 3],
@@ -112,9 +72,59 @@ pub unsafe fn check_local_static_0() {
11272
},
11373
x: 0_i32,
11474
fn_: None,
75+
}
76+
};
77+
pub static mut static_inner_array: [Inner; 2] = unsafe {
78+
[Inner {
79+
v: 0_i32,
80+
name: std::ptr::null(),
81+
}; 2]
82+
};
83+
pub static mut static_foo: Foo = unsafe {
84+
Foo {
85+
s1: b"hello\0".as_ptr(),
86+
s2: std::ptr::null(),
87+
fn1: None,
88+
fn2: None,
89+
n: 42,
90+
}
91+
};
92+
pub static mut static_foo_array: [Foo; 2] = unsafe {
93+
[
94+
Foo {
95+
s1: b"first\0".as_ptr(),
96+
s2: std::ptr::null(),
97+
fn1: None,
98+
fn2: None,
99+
n: 1,
100+
},
101+
Foo {
102+
s1: b"second\0".as_ptr(),
103+
s2: std::ptr::null(),
104+
fn1: None,
105+
fn2: None,
106+
n: 2,
107+
},
108+
]
109+
};
110+
pub unsafe fn check_local_static_0() {
111+
static mut local_outer: Outer = unsafe {
112+
Outer {
113+
p1: std::ptr::null_mut(),
114+
p2: std::ptr::null(),
115+
arr: [std::ptr::null_mut(); 3],
116+
cp: std::ptr::null(),
117+
pp: std::ptr::null_mut(),
118+
inner: Inner {
119+
v: 0_i32,
120+
name: std::ptr::null(),
121+
},
122+
x: 0_i32,
123+
fn_: None,
124+
}
115125
};;
116-
static mut local_fn: Option<unsafe fn(i32) -> i32> = None;;
117-
static mut local_p: *mut i32 = std::ptr::null_mut();;
126+
static mut local_fn: Option<unsafe fn(i32) -> i32> = unsafe { None };;
127+
static mut local_p: *mut i32 = unsafe { std::ptr::null_mut() };;
118128
assert!((local_outer.p1).is_null());
119129
assert!((local_outer.fn_).is_none());
120130
assert!((local_fn).is_none());

tests/unit/out/unsafe/enum_int_interop.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,28 @@ pub struct Entry {
6666
pub color: Color,
6767
pub opt: Option,
6868
}
69-
pub static mut global_color: Color = Color::GREEN;
70-
pub static mut global_opt: Option = Option::OPT_B;
71-
pub static mut global_tag: Tag = Tag::TAG_TWO;
72-
pub static mut entries: [Entry; 3] = [
73-
Entry {
74-
name: b"first\0".as_ptr(),
75-
color: Color::RED,
76-
opt: Option::OPT_NONE,
77-
},
78-
Entry {
79-
name: b"second\0".as_ptr(),
80-
color: Color::GREEN,
81-
opt: Option::OPT_A,
82-
},
83-
Entry {
84-
name: b"third\0".as_ptr(),
85-
color: Color::BLUE,
86-
opt: Option::OPT_C,
87-
},
88-
];
69+
pub static mut global_color: Color = unsafe { Color::GREEN };
70+
pub static mut global_opt: Option = unsafe { Option::OPT_B };
71+
pub static mut global_tag: Tag = unsafe { Tag::TAG_TWO };
72+
pub static mut entries: [Entry; 3] = unsafe {
73+
[
74+
Entry {
75+
name: b"first\0".as_ptr(),
76+
color: Color::RED,
77+
opt: Option::OPT_NONE,
78+
},
79+
Entry {
80+
name: b"second\0".as_ptr(),
81+
color: Color::GREEN,
82+
opt: Option::OPT_A,
83+
},
84+
Entry {
85+
name: b"third\0".as_ptr(),
86+
color: Color::BLUE,
87+
opt: Option::OPT_C,
88+
},
89+
]
90+
};
8991
pub unsafe fn as_int_0(mut c: Color) -> i32 {
9092
return (c as i32);
9193
}

tests/unit/out/unsafe/enum_int_interop_c.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,28 @@ pub struct Entry {
6666
pub color: Color,
6767
pub opt: Option,
6868
}
69-
pub static mut global_color: Color = Color::GREEN;
70-
pub static mut global_opt: Option = Option::OPT_B;
71-
pub static mut global_tag: Tag = Tag::TAG_TWO;
72-
pub static mut entries: [Entry; 3] = [
73-
Entry {
74-
name: b"first\0".as_ptr().cast_mut().cast_const(),
75-
color: Color::RED,
76-
opt: Option::OPT_NONE,
77-
},
78-
Entry {
79-
name: b"second\0".as_ptr().cast_mut().cast_const(),
80-
color: Color::GREEN,
81-
opt: Option::OPT_A,
82-
},
83-
Entry {
84-
name: b"third\0".as_ptr().cast_mut().cast_const(),
85-
color: Color::BLUE,
86-
opt: Option::OPT_C,
87-
},
88-
];
69+
pub static mut global_color: Color = unsafe { Color::GREEN };
70+
pub static mut global_opt: Option = unsafe { Option::OPT_B };
71+
pub static mut global_tag: Tag = unsafe { Tag::TAG_TWO };
72+
pub static mut entries: [Entry; 3] = unsafe {
73+
[
74+
Entry {
75+
name: b"first\0".as_ptr().cast_mut().cast_const(),
76+
color: Color::RED,
77+
opt: Option::OPT_NONE,
78+
},
79+
Entry {
80+
name: b"second\0".as_ptr().cast_mut().cast_const(),
81+
color: Color::GREEN,
82+
opt: Option::OPT_A,
83+
},
84+
Entry {
85+
name: b"third\0".as_ptr().cast_mut().cast_const(),
86+
color: Color::BLUE,
87+
opt: Option::OPT_C,
88+
},
89+
]
90+
};
8991
pub unsafe fn as_int_0(mut c: Color) -> i32 {
9092
return (c as i32);
9193
}

tests/unit/out/unsafe/fn_ptr_global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub unsafe fn double_it_0(mut x: i32) -> i32 {
1212
pub unsafe fn triple_it_1(mut x: i32) -> i32 {
1313
return ((x) * (3));
1414
}
15-
pub static mut g_op: Option<unsafe fn(i32) -> i32> = None;
15+
pub static mut g_op: Option<unsafe fn(i32) -> i32> = unsafe { None };
1616
pub unsafe fn set_op_2(mut fn_: Option<unsafe fn(i32) -> i32>) {
1717
g_op = fn_;
1818
}

tests/unit/out/unsafe/fn_ptr_vtable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Default for Vtable {
2222
}
2323
}
2424
}
25-
pub static mut storage: i32 = 0_i32;
25+
pub static mut storage: i32 = unsafe { 0_i32 };
2626
pub unsafe fn int_create_0(mut val: i32) -> *mut ::libc::c_void {
2727
storage = val;
2828
return ((&raw mut storage as *mut i32) as *mut i32 as *mut ::libc::c_void);

tests/unit/out/unsafe/global_pointers.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,31 @@ pub struct Entry {
1212
pub name: *const u8,
1313
pub p: *mut i32,
1414
}
15-
pub static mut single_entry: Entry = Entry {
16-
name: b"alone\0".as_ptr(),
17-
p: std::ptr::null_mut(),
18-
};
19-
pub static mut entries: [Entry; 2] = [
20-
Entry {
21-
name: b"first\0".as_ptr(),
22-
p: std::ptr::null_mut(),
23-
},
15+
pub static mut single_entry: Entry = unsafe {
2416
Entry {
25-
name: b"second\0".as_ptr(),
17+
name: b"alone\0".as_ptr(),
2618
p: std::ptr::null_mut(),
27-
},
28-
];
29-
pub static mut arr_of_pointers: [*mut u8; 3] = [
30-
std::ptr::null_mut(),
31-
std::ptr::null_mut(),
32-
std::ptr::null_mut(),
33-
];
19+
}
20+
};
21+
pub static mut entries: [Entry; 2] = unsafe {
22+
[
23+
Entry {
24+
name: b"first\0".as_ptr(),
25+
p: std::ptr::null_mut(),
26+
},
27+
Entry {
28+
name: b"second\0".as_ptr(),
29+
p: std::ptr::null_mut(),
30+
},
31+
]
32+
};
33+
pub static mut arr_of_pointers: [*mut u8; 3] = unsafe {
34+
[
35+
std::ptr::null_mut(),
36+
std::ptr::null_mut(),
37+
std::ptr::null_mut(),
38+
]
39+
};
3440
pub fn main() {
3541
unsafe {
3642
std::process::exit(main_0() as i32);

tests/unit/out/unsafe/global_without_initializer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use std::rc::Rc;
1111
pub struct S {
1212
pub a: i32,
1313
}
14-
pub static mut s: *mut S = std::ptr::null_mut();
15-
pub static mut file: *mut ::std::fs::File = std::ptr::null_mut();
16-
pub static mut size: u64 = 0_u64;
14+
pub static mut s: *mut S = unsafe { std::ptr::null_mut() };
15+
pub static mut file: *mut ::std::fs::File = unsafe { std::ptr::null_mut() };
16+
pub static mut size: u64 = unsafe { 0_u64 };
1717
pub fn main() {
1818
unsafe {
1919
std::process::exit(main_0() as i32);

0 commit comments

Comments
 (0)