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