Skip to content

Commit 744bba0

Browse files
committed
---
yaml --- r: 63847 b: refs/heads/snap-stage3 c: 9340fd5 h: refs/heads/master i: 63845: 9b74613 63843: bb3aa58 63839: c0ead60 v: v3
1 parent 93bc555 commit 744bba0

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: c05165bf93e05a8473461716579c47355bd1659d
4+
refs/heads/snap-stage3: 9340fd5ce0d7bd0f1bbfbda73944920bcc1364eb
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
pub trait Clone2 {
12+
fn clone(&self) -> Self;
13+
}
14+
15+
16+
trait Getter<T: Clone2> {
17+
fn get(&self) -> T;
18+
}
19+
20+
impl Getter<int> for int { //~ ERROR failed to find an implementation of trait Clone2 for int
21+
fn get(&self) -> int { *self }
22+
}
23+
24+
fn main() { }
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
#[allow(default_methods)]
12+
trait Speak {
13+
fn say(&self, s:&str) -> ~str;
14+
fn hi(&self) -> ~str { hello(self) }
15+
}
16+
17+
fn hello<S:Speak>(s:&S) -> ~str{
18+
s.say("hello")
19+
}
20+
21+
impl Speak for int {
22+
fn say(&self, s:&str) -> ~str {
23+
fmt!("%s: %d", s, *self)
24+
}
25+
}
26+
27+
impl<T: Speak> Speak for Option<T> {
28+
fn say(&self, s:&str) -> ~str {
29+
match *self {
30+
None => fmt!("%s - none", s),
31+
Some(ref x) => { ~"something!" + x.say(s) }
32+
}
33+
}
34+
}
35+
36+
37+
fn main() {
38+
assert_eq!(3.hi(), ~"hello: 3");
39+
assert_eq!(Some(Some(3)).hi(), ~"something!something!hello: 3");
40+
assert_eq!(None::<int>.hi(), ~"hello - none");
41+
42+
// These fail because of a bug in monomorphization's ID generation.
43+
//assert_eq!(Some(None::<int>).hi(), ~"something!hello - none");
44+
//assert_eq!(Some(3).hi(), ~"something!hello: 3");
45+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
pub trait Clone2 {
12+
/// Returns a copy of the value. The contents of owned pointers
13+
/// are copied to maintain uniqueness, while the contents of
14+
/// managed pointers are not copied.
15+
fn clone(&self) -> Self;
16+
}
17+
18+
#[allow(default_methods)]
19+
trait 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+
29+
impl Getter<int> for int {
30+
fn do_get(&self) -> int { *self }
31+
}
32+
33+
impl<T: Clone> Getter<T> for Option<T> {
34+
fn do_get(&self) -> T { self.get_ref().clone() }
35+
}
36+
37+
38+
fn main() {
39+
assert_eq!(3.do_get2(), (3, 3));
40+
assert_eq!(Some(~"hi").do_get2(), (~"hi", ~"hi"));
41+
}

0 commit comments

Comments
 (0)