Skip to content

Commit 91e99a3

Browse files
committed
Add a test
1 parent f55dafe commit 91e99a3

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/test/run-pass/builtin-clone.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that `Clone` is correctly implemented for builtin types.
12+
// Also test that cloning an array or a tuple is done right, i.e.
13+
// each component is cloned.
14+
15+
fn test_clone<T: Clone>(arg: T) {
16+
let _ = arg.clone();
17+
}
18+
19+
fn foo() { }
20+
21+
#[derive(Debug, PartialEq, Eq)]
22+
struct S(i32);
23+
24+
impl Clone for S {
25+
fn clone(&self) -> Self {
26+
S(self.0 + 1)
27+
}
28+
}
29+
30+
fn main() {
31+
test_clone(foo);
32+
test_clone([1; 56]);
33+
test_clone((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1));
34+
35+
let a = [S(0), S(1), S(2)];
36+
let b = [S(1), S(2), S(3)];
37+
assert_eq!(b, a.clone());
38+
39+
let a = (
40+
(S(1), S(0)),
41+
(
42+
(S(0), S(0), S(1)),
43+
S(0)
44+
)
45+
);
46+
let b = (
47+
(S(2), S(1)),
48+
(
49+
(S(1), S(1), S(2)),
50+
S(1)
51+
)
52+
);
53+
assert_eq!(b, a.clone());
54+
}

0 commit comments

Comments
 (0)