]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
970d7e83 LB |
2 | |
3 | pub trait Clone2 { | |
62682a34 | 4 | /// Returns a copy of the value. The contents of boxes |
970d7e83 LB |
5 | /// are copied to maintain uniqueness, while the contents of |
6 | /// managed pointers are not copied. | |
7 | fn clone(&self) -> Self; | |
8 | } | |
9 | ||
970d7e83 LB |
10 | trait Getter<T: Clone> { |
11 | fn do_get(&self) -> T; | |
12 | ||
13 | fn do_get2(&self) -> (T, T) { | |
14 | let x = self.do_get(); | |
15 | (x.clone(), x.clone()) | |
16 | } | |
17 | ||
18 | } | |
19 | ||
c34b1796 AL |
20 | impl Getter<isize> for isize { |
21 | fn do_get(&self) -> isize { *self } | |
970d7e83 LB |
22 | } |
23 | ||
24 | impl<T: Clone> Getter<T> for Option<T> { | |
1a4d82fc | 25 | fn do_get(&self) -> T { self.as_ref().unwrap().clone() } |
970d7e83 LB |
26 | } |
27 | ||
28 | ||
1a4d82fc | 29 | pub fn main() { |
970d7e83 | 30 | assert_eq!(3.do_get2(), (3, 3)); |
1a4d82fc | 31 | assert_eq!(Some("hi".to_string()).do_get2(), ("hi".to_string(), "hi".to_string())); |
970d7e83 | 32 | } |