aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/execute/torture/derive_macro4.rs
blob: 38c4808574a33463a067bea12df00da88b9e24b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#[lang = "sized"]
pub trait Sized {}

#[lang = "clone"]
pub trait Clone {
    fn clone(&self) -> Self;
}

#[derive(Clone)]
struct Foo {
    a: i32,
}

#[derive(Clone)]
struct S {
    a: i32,
    b: Foo,
}

impl Clone for i32 {
    fn clone(&self) -> Self { *self }
}

fn main() -> i32 {
    let s1 = S { a: 15, b: Foo { a: 14 }};
    let s2 = s1.clone();

    let l = s1.a - s2.a;
    let r = s1.b.a - s2.b.a;

    // should be 0 if all fields were cloned correctly
    l + r
}