]>
Commit | Line | Data |
---|---|---|
f2b60f7d FG |
1 | // check-pass |
2 | ||
3 | #![feature(return_position_impl_trait_in_trait)] | |
4 | #![allow(incomplete_features)] | |
5 | ||
6 | use std::fmt::Display; | |
7 | ||
8 | trait Foo { | |
9 | fn bar(&self) -> impl Display; | |
10 | } | |
11 | ||
12 | impl Foo for i32 { | |
13 | fn bar(&self) -> i32 { | |
14 | *self | |
15 | } | |
16 | } | |
17 | ||
18 | impl Foo for &'static str { | |
19 | fn bar(&self) -> &'static str { | |
20 | *self | |
21 | } | |
22 | } | |
23 | ||
24 | struct Yay; | |
25 | ||
26 | impl Foo for Yay { | |
27 | fn bar(&self) -> String { | |
28 | String::from(":^)") | |
29 | } | |
30 | } | |
31 | ||
32 | fn foo_generically<T: Foo>(t: T) { | |
33 | println!("{}", t.bar()); | |
34 | } | |
35 | ||
36 | fn main() { | |
37 | println!("{}", "Hello, world.".bar()); | |
38 | println!("The answer is {}!", 42.bar()); | |
39 | foo_generically(Yay); | |
40 | } |