Debian Codegraph @

gcc/testsuite/rust/execute/torture/derive_clone_enum1.rs

raw
1 #[lang = "clone"]
2 trait Clone {
3 pub fn clone(&self) -> Self;
4 }
5
6 impl Clone for i32 {
7 fn clone(&self) -> Self {
8 *self
9 }
10 }
11
12 #[derive(Clone)]
13 enum MixAndMatch {
14 A,
15 B(i32),
16 C { inner: i32 }
17 }
18
19 fn main() -> i32 {
20 let a = MixAndMatch::A;
21 let a_copy = a.clone();
22
23 // we want res to stay at zero - when we don't match on the right thing, increase it
24
25 let mut res = match a_copy {
26 MixAndMatch::A => 0,
27 _ => 1,
28 };
29
30 let a = MixAndMatch::B(15);
31 let a_copy = a.clone();
32
33 match a_copy {
34 MixAndMatch::B(15) => {},
35 _ => res += 1,
36 };
37
38 let a = MixAndMatch::C { inner: 15 };
39 let a_copy = a.clone();
40
41 match a_copy {
42 MixAndMatch::C { inner } => {
43 if inner != 15 {
44 res += 1;
45 }
46 },
47 _ => res += 1,
48 };
49
50 res
51 }