Skip to content

Commit 8744403

Browse files
committed
Update tests
1 parent 2e920ee commit 8744403

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎tests/unit/out/refcount/self_referencing_initializer.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ impl Default for node_with_defaults {
3939
}
4040
}
4141
}
42+
pub fn init_0(mut l: Ptr<list_head>) -> Ptr<list_head> {
43+
field!(l, next).write(Ptr::<list_head>::null());
44+
return l;
45+
}
4246
pub fn main() {
4347
__cpp2rust_init_globals();
4448
std::process::exit(main_0());
@@ -87,6 +91,11 @@ fn main_0() -> i32 {
8791
};
8892
assert!(({ { (*d.borrow()).next.clone() } } == { (d.as_pointer()) }));
8993
assert!(({ (*d.borrow()).value } == 3));
94+
let called: Value<list_head> = <Value<list_head>>::default();
95+
*called.borrow_mut() = list_head {
96+
next: ({ init_0((called.as_pointer())) }),
97+
};
98+
assert!(({ { (*called.borrow()).next.clone() } } == { (called.as_pointer()) }));
9099
let mut size: usize = ::std::mem::size_of::<usize>();
91100
assert!((size == ::std::mem::size_of::<usize>()));
92101
return 0;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ impl Default for node_with_defaults {
3131
}
3232
}
3333
}
34+
pub unsafe fn init_0(mut l: *mut list_head) -> *mut list_head {
35+
(*l).next = std::ptr::null_mut();
36+
return l;
37+
}
3438
pub fn main() {
3539
unsafe {
3640
__cpp2rust_init_globals();
@@ -69,6 +73,11 @@ unsafe fn main_0() -> i32 {
6973
};
7074
assert!(((d.next) == (&mut d as *mut node_with_defaults)));
7175
assert!(((d.value) == (3)));
76+
let mut called: list_head = <list_head>::default();
77+
called = list_head {
78+
next: (unsafe { init_0((&mut called as *mut list_head)) }),
79+
};
80+
assert!(((called.next) == (&mut called as *mut list_head)));
7281
let mut size: usize = ::std::mem::size_of::<usize>();
7382
assert!(((size) == (::std::mem::size_of::<usize>())));
7483
return 0;

‎tests/unit/self_referencing_initializer.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ struct node_with_defaults {
1515
int value = 3;
1616
};
1717

18+
static list_head *init(list_head *l) {
19+
l->next = nullptr;
20+
return l;
21+
}
22+
1823
int main() {
1924
list_head list = {&list};
2025
assert(list.next == &list);
@@ -32,6 +37,9 @@ int main() {
3237
assert(d.next == &d);
3338
assert(d.value == 3);
3439

40+
list_head called = {init(&called)};
41+
assert(called.next == &called);
42+
3543
size_t size = sizeof(size);
3644
assert(size == sizeof(size_t));
3745

0 commit comments

Comments
 (0)