Skip to content

Commit e715899

Browse files
committed
Update tests
1 parent e0521d6 commit e715899

2 files changed

Lines changed: 28 additions & 21 deletions

File tree

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl Default for Holder {
111111
}
112112
}
113113
}
114-
#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, Default)]
114+
#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, Default)]
115115
#[byte_size(4)]
116116
pub struct Box_int_ {
117117
#[offset(0)]
@@ -122,26 +122,32 @@ impl Box_int_ {
122122
let v: Value<i32> = Rc::new(RefCell::new(v));
123123
Self { val: (*v.borrow()) }
124124
}
125+
pub fn copy_from(o: Ptr<Box_int_>) -> Self {
126+
Self {
127+
val: o.with(|__s| __s.val),
128+
}
129+
}
125130
pub fn move_from(_a0: Ptr<Box_int_>) -> Self {
126131
Self {
127132
val: { (*_a0.upgrade().deref()).val },
128133
}
129134
}
130135
}
131-
#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, Default)]
136+
impl Clone for Box_int_ {
137+
fn clone(&self) -> Self {
138+
let __src: Value<Box_int_> = Rc::new(RefCell::new(Box_int_ {
139+
val: self.val.clone(),
140+
}));
141+
Box_int_::copy_from(__src.as_pointer())
142+
}
143+
}
144+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
132145
#[byte_size(4)]
133146
pub struct Owner {
134147
#[offset(0)]
135148
#[byte_size(4)]
136149
pub box_: Box_int_,
137150
}
138-
impl Owner {
139-
pub fn move_from(_a0: Ptr<Owner>) -> Self {
140-
Self {
141-
box_: Box_int_::move_from({ field_ptr!(_a0, box_) }),
142-
}
143-
}
144-
}
145151
#[derive(Record, ByteRepr, VaArg, FnPtrArg, Default)]
146152
#[byte_size(4)]
147153
pub struct OutOfLine {
@@ -235,7 +241,7 @@ fn main_0() -> i32 {
235241
let o: Value<Owner> = Rc::new(RefCell::new(Owner {
236242
box_: Box_int_::new({ 3 }),
237243
}));
238-
let mut o2: Owner = Owner::move_from({ o.as_pointer() });
244+
let mut o2: Owner = (*o.borrow()).clone();
239245
assert!((o2.box_.val == 3));
240246
let ol1: Value<OutOfLine> = Rc::new(RefCell::new(OutOfLine::new({ 5 })));
241247
let mut ol2: OutOfLine = OutOfLine::copy_from({ ol1.as_pointer() });

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub struct Holder {
8989
pub arr: [Counted; 2],
9090
}
9191
#[repr(C)]
92-
#[derive(FnPtrArg, MoveCtorUnsafe, Default)]
92+
#[derive(VaArg, FnPtrArg, MoveCtorUnsafe, Default)]
9393
pub struct Box_int_ {
9494
pub val: i32,
9595
}
@@ -98,24 +98,25 @@ impl Box_int_ {
9898
let mut this = Self { val: v };
9999
this
100100
}
101+
pub unsafe fn copy_from(o: *const Box_int_) -> Self {
102+
let mut this = Self { val: (*o).val };
103+
this
104+
}
101105
pub unsafe fn move_from(_a0: *mut Box_int_) -> Self {
102106
let mut this = Self { val: (*_a0).val };
103107
this
104108
}
105109
}
110+
impl Clone for Box_int_ {
111+
fn clone(&self) -> Self {
112+
unsafe { Box_int_::copy_from(self as *const Box_int_) }
113+
}
114+
}
106115
#[repr(C)]
107-
#[derive(FnPtrArg, MoveCtorUnsafe, Default)]
116+
#[derive(Clone, VaArg, FnPtrArg, Default)]
108117
pub struct Owner {
109118
pub box_: Box_int_,
110119
}
111-
impl Owner {
112-
pub unsafe fn move_from(_a0: *mut Owner) -> Self {
113-
let mut this = Self {
114-
box_: Box_int_::move_from({ &mut (*_a0).box_ }),
115-
};
116-
this
117-
}
118-
}
119120
#[repr(C)]
120121
#[derive(VaArg, FnPtrArg, Default)]
121122
pub struct OutOfLine {
@@ -196,7 +197,7 @@ unsafe fn main_0() -> i32 {
196197
let mut o: Owner = Owner {
197198
box_: Box_int_::new({ 3 }),
198199
};
199-
let mut o2: Owner = Owner::move_from({ &mut o });
200+
let mut o2: Owner = o.clone();
200201
assert!(((o2.box_.val) == (3)));
201202
let mut ol1: OutOfLine = OutOfLine::new({ 5 });
202203
let mut ol2: OutOfLine = OutOfLine::copy_from({ &ol1 });

0 commit comments

Comments
 (0)