]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/trait-with-bounds-default.rs
Imported Upstream version 1.2.0+dfsg1
[rustc.git] / src / test / run-pass / trait-with-bounds-default.rs
CommitLineData
970d7e83
LB
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.
1a4d82fc 10//
970d7e83
LB
11
12pub trait Clone2 {
62682a34 13 /// Returns a copy of the value. The contents of boxes
970d7e83
LB
14 /// are copied to maintain uniqueness, while the contents of
15 /// managed pointers are not copied.
16 fn clone(&self) -> Self;
17}
18
970d7e83
LB
19trait Getter<T: Clone> {
20 fn do_get(&self) -> T;
21
22 fn do_get2(&self) -> (T, T) {
23 let x = self.do_get();
24 (x.clone(), x.clone())
25 }
26
27}
28
c34b1796
AL
29impl Getter<isize> for isize {
30 fn do_get(&self) -> isize { *self }
970d7e83
LB
31}
32
33impl<T: Clone> Getter<T> for Option<T> {
1a4d82fc 34 fn do_get(&self) -> T { self.as_ref().unwrap().clone() }
970d7e83
LB
35}
36
37
1a4d82fc 38pub fn main() {
970d7e83 39 assert_eq!(3.do_get2(), (3, 3));
1a4d82fc 40 assert_eq!(Some("hi".to_string()).do_get2(), ("hi".to_string(), "hi".to_string()));
970d7e83 41}