]> git.lizzy.rs Git - rust.git/blob - src/test/ui/methods/method-projection.rs
move an `assert!` to the right place
[rust.git] / src / test / ui / methods / method-projection.rs
1 // run-pass
2 // Test that we can use method notation to call methods based on a
3 // projection bound from a trait. Issue #20469.
4
5 trait MakeString {
6     fn make_string(&self) -> String;
7 }
8
9 impl MakeString for isize {
10     fn make_string(&self) -> String {
11         format!("{}", *self)
12     }
13 }
14
15 impl MakeString for usize {
16     fn make_string(&self) -> String {
17         format!("{}", *self)
18     }
19 }
20
21 trait Foo {
22     type F: MakeString;
23
24     fn get(&self) -> &Self::F;
25 }
26
27 fn foo<F:Foo>(f: &F) -> String {
28     f.get().make_string()
29 }
30
31 struct SomeStruct {
32     field: isize,
33 }
34
35 impl Foo for SomeStruct {
36     type F = isize;
37
38     fn get(&self) -> &isize {
39         &self.field
40     }
41 }
42
43 struct SomeOtherStruct {
44     field: usize,
45 }
46
47 impl Foo for SomeOtherStruct {
48     type F = usize;
49
50     fn get(&self) -> &usize {
51         &self.field
52     }
53 }
54
55 fn main() {
56     let x = SomeStruct { field: 22 };
57     assert_eq!(foo(&x), format!("22"));
58
59     let x = SomeOtherStruct { field: 44 };
60     assert_eq!(foo(&x), format!("44"));
61 }