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