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