Skip to content

Commit 609af4f

Browse files
committed
Update tests
1 parent 7b1808b commit 609af4f

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ pub struct Derived {
2323
pub factor: i32,
2424
}
2525
impl Derived {}
26+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
27+
#[byte_size(8)]
28+
pub struct Pair {
29+
#[offset(0)]
30+
pub first: i32,
31+
#[offset(4)]
32+
pub second: i32,
33+
}
34+
pub fn pair_diff_0(mut p: Ptr<Pair>) -> i32 {
35+
return ({ p.with(|__s| __s.first) } - { p.with(|__s| __s.second) });
36+
}
2637
pub fn main() {
2738
__cpp2rust_init_globals();
2839
std::process::exit(main_0());
@@ -36,6 +47,12 @@ fn main_0() -> i32 {
3647
let derived: Value<Derived> = Rc::new(RefCell::new(Derived::new({ 3 })));
3748
let mut base: PtrDyn<dyn Base> = (derived.as_pointer()).to_dyn::<dyn Base>(|w| w);
3849
assert!((({ (*base.upgrade().deref_mut()).apply(5,) }) == 15));
50+
let pair: Value<Pair> = Rc::new(RefCell::new(Pair {
51+
first: 7,
52+
second: 3,
53+
}));
54+
assert!((({ pair_sum_1((pair.as_pointer()),) }) == 10));
55+
assert!((({ pair_diff_0((pair.as_pointer()),) }) == 4));
3956
return 0;
4057
}
4158
impl S {
@@ -50,6 +67,9 @@ impl Derived {
5067
}
5168
impl S {}
5269
impl Derived {}
70+
pub fn pair_sum_1(mut p: Ptr<Pair>) -> i32 {
71+
return ({ p.with(|__s| __s.first) } + { p.with(|__s| __s.second) });
72+
}
5373
impl Base for Derived {
5474
fn apply(&mut self, mut x: i32) -> i32 {
5575
return ({ self.factor } * x);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ pub struct Derived {
2525
pub factor: i32,
2626
}
2727
impl Derived {}
28+
#[repr(C)]
29+
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
30+
pub struct Pair {
31+
pub first: i32,
32+
pub second: i32,
33+
}
34+
pub unsafe fn pair_diff_0(mut p: *const Pair) -> i32 {
35+
return (((*p).first) - ((*p).second));
36+
}
2837
pub fn main() {
2938
unsafe {
3039
__cpp2rust_init_globals();
@@ -40,6 +49,12 @@ unsafe fn main_0() -> i32 {
4049
let mut derived: Derived = Derived::new({ 3 });
4150
let mut base: *mut dyn Base = (&mut derived as *mut Derived);
4251
assert!(((unsafe { (*base).apply(5,) }) == (15)));
52+
let mut pair: Pair = Pair {
53+
first: 7,
54+
second: 3,
55+
};
56+
assert!(((unsafe { pair_sum_1((&mut pair as *mut Pair).cast_const(),) }) == (10)));
57+
assert!(((unsafe { pair_diff_0((&mut pair as *mut Pair).cast_const(),) }) == (4)));
4358
return 0;
4459
}
4560
impl S {
@@ -70,6 +85,9 @@ impl S {
7085
}
7186
}
7287
impl Derived {}
88+
pub unsafe fn pair_sum_1(mut p: *const Pair) -> i32 {
89+
return (((*p).first) + ((*p).second));
90+
}
7391
unsafe impl Base for Derived {
7492
unsafe fn apply(&mut self, x: i32) -> i32 {
7593
return ((self.factor) * (x));

0 commit comments

Comments
 (0)