]> git.proxmox.com Git - rustc.git/blame - src/test/ui/traits/bug-7183-generics.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / traits / bug-7183-generics.rs
CommitLineData
416331ca
XL
1// run-pass
2
1a4d82fc
JJ
3trait Speak : Sized {
4 fn say(&self, s:&str) -> String;
5 fn hi(&self) -> String { hello(self) }
970d7e83
LB
6}
7
1a4d82fc 8fn hello<S:Speak>(s:&S) -> String{
970d7e83
LB
9 s.say("hello")
10}
11
c34b1796 12impl Speak for isize {
1a4d82fc
JJ
13 fn say(&self, s:&str) -> String {
14 format!("{}: {}", s, *self)
970d7e83
LB
15 }
16}
17
18impl<T: Speak> Speak for Option<T> {
1a4d82fc 19 fn say(&self, s:&str) -> String {
970d7e83 20 match *self {
1a4d82fc
JJ
21 None => format!("{} - none", s),
22 Some(ref x) => { format!("something!{}", x.say(s)) }
970d7e83
LB
23 }
24 }
25}
26
27
1a4d82fc 28pub fn main() {
85aaf69f
SL
29 assert_eq!(3.hi(), "hello: 3".to_string());
30 assert_eq!(Some(Some(3)).hi(),
1a4d82fc 31 "something!something!hello: 3".to_string());
c34b1796 32 assert_eq!(None::<isize>.hi(), "hello - none".to_string());
970d7e83 33
c34b1796 34 assert_eq!(Some(None::<isize>).hi(), "something!hello - none".to_string());
85aaf69f 35 assert_eq!(Some(3).hi(), "something!hello: 3".to_string());
970d7e83 36}