]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-13323.rs
Rollup merge of #100168 - WaffleLapkin:improve_diagnostics_for_missing_type_in_a_cons...
[rust.git] / src / test / ui / issues / issue-13323.rs
1 // run-pass
2 #![feature(box_syntax)]
3
4 struct StrWrap {
5     s: String
6 }
7
8 impl StrWrap {
9     fn new(s: &str) -> StrWrap {
10         StrWrap { s: s.to_string() }
11     }
12
13     fn get_s<'a>(&'a self) -> &'a str {
14         &self.s
15     }
16 }
17
18 struct MyStruct {
19     s: StrWrap
20 }
21
22 impl MyStruct {
23     fn new(s: &str) -> MyStruct {
24         MyStruct { s: StrWrap::new(s) }
25     }
26
27     fn get_str_wrap<'a>(&'a self) -> &'a StrWrap {
28         &self.s
29     }
30 }
31
32 trait Matcher<T> {
33     fn matches(&self, actual: T) -> bool;
34 }
35
36 fn assert_that<T, U: Matcher<T>>(actual: T, matcher: &U) {
37     assert!(matcher.matches(actual));
38 }
39
40 struct EqualTo<T> {
41     expected: T
42 }
43
44 impl<T: Eq> Matcher<T> for EqualTo<T> {
45     fn matches(&self, actual: T) -> bool {
46         self.expected.eq(&actual)
47     }
48 }
49
50 fn equal_to<T: Eq>(expected: T) -> Box<EqualTo<T>> {
51     box EqualTo { expected: expected }
52 }
53
54 pub fn main() {
55     let my_struct = MyStruct::new("zomg");
56     let s = my_struct.get_str_wrap();
57
58     assert_that(s.get_s(), &*equal_to("zomg"));
59 }