]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/builtin-clone.rs
New upstream version 1.33.0+dfsg1
[rustc.git] / src / test / run-pass / builtin-clone.rs
CommitLineData
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
5fn test_clone<T: Clone>(arg: T) {
6 let _ = arg.clone();
7}
8
9fn foo() { }
10
11#[derive(Debug, PartialEq, Eq)]
12struct S(i32);
13
14impl Clone for S {
15 fn clone(&self) -> Self {
16 S(self.0 + 1)
17 }
18}
19
20fn 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}