]>
Commit | Line | Data |
---|---|---|
3b2f2976 XL |
1 | // Test that `Clone` is correctly implemented for builtin types. |
2 | // Also test that cloning an array or a tuple is done right, i.e. | |
3 | // each component is cloned. | |
4 | ||
5 | fn test_clone<T: Clone>(arg: T) { | |
6 | let _ = arg.clone(); | |
7 | } | |
8 | ||
9 | fn foo() { } | |
10 | ||
11 | #[derive(Debug, PartialEq, Eq)] | |
12 | struct S(i32); | |
13 | ||
14 | impl Clone for S { | |
15 | fn clone(&self) -> Self { | |
16 | S(self.0 + 1) | |
17 | } | |
18 | } | |
19 | ||
20 | fn main() { | |
21 | test_clone(foo); | |
22 | test_clone([1; 56]); | |
23 | test_clone((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)); | |
24 | ||
25 | let a = [S(0), S(1), S(2)]; | |
26 | let b = [S(1), S(2), S(3)]; | |
27 | assert_eq!(b, a.clone()); | |
28 | ||
29 | let a = ( | |
30 | (S(1), S(0)), | |
31 | ( | |
32 | (S(0), S(0), S(1)), | |
33 | S(0) | |
34 | ) | |
35 | ); | |
36 | let b = ( | |
37 | (S(2), S(1)), | |
38 | ( | |
39 | (S(1), S(1), S(2)), | |
40 | S(1) | |
41 | ) | |
42 | ); | |
43 | assert_eq!(b, a.clone()); | |
44 | } |