]> git.lizzy.rs Git - rust.git/blob - src/test/ui/bug-7183-generics.rs
Merge branch 'master' into rusty-hermit
[rust.git] / src / test / ui / bug-7183-generics.rs
1 // run-pass
2
3 trait Speak : Sized {
4     fn say(&self, s:&str) -> String;
5     fn hi(&self) -> String { hello(self) }
6 }
7
8 fn hello<S:Speak>(s:&S) -> String{
9     s.say("hello")
10 }
11
12 impl Speak for isize {
13     fn say(&self, s:&str) -> String {
14         format!("{}: {}", s, *self)
15     }
16 }
17
18 impl<T: Speak> Speak for Option<T> {
19     fn say(&self, s:&str) -> String {
20         match *self {
21             None => format!("{} - none", s),
22             Some(ref x) => { format!("something!{}", x.say(s)) }
23         }
24     }
25 }
26
27
28 pub fn main() {
29     assert_eq!(3.hi(), "hello: 3".to_string());
30     assert_eq!(Some(Some(3)).hi(),
31                "something!something!hello: 3".to_string());
32     assert_eq!(None::<isize>.hi(), "hello - none".to_string());
33
34     assert_eq!(Some(None::<isize>).hi(), "something!hello - none".to_string());
35     assert_eq!(Some(3).hi(), "something!hello: 3".to_string());
36 }