]> git.lizzy.rs Git - rust.git/blob - tests/ui/associated-types/associated-types-in-inherent-method.rs
Auto merge of #107257 - inquisitivecrystal:ffi-attr, r=davidtwco
[rust.git] / tests / ui / associated-types / associated-types-in-inherent-method.rs
1 // run-pass
2
3 trait Get {
4     type Value;
5     fn get(&self) -> &<Self as Get>::Value;
6 }
7
8 struct Struct {
9     x: isize,
10 }
11
12 impl Get for Struct {
13     type Value = isize;
14     fn get(&self) -> &isize {
15         &self.x
16     }
17 }
18
19 impl Struct {
20     fn grab<T:Get>(x: &T) -> &<T as Get>::Value {
21         x.get()
22     }
23 }
24
25 fn main() {
26     let s = Struct {
27         x: 100,
28     };
29     assert_eq!(*Struct::grab(&s), 100);
30 }