]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-sugar-path.rs
feat(rustdoc): open sidebar menu when links inside it are focused
[rust.git] / src / test / ui / associated-types / associated-types-sugar-path.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_variables)]
4 #![allow(unused_imports)]
5 // Test paths to associated types using the type-parameter-only sugar.
6
7 use std::ops::Deref;
8
9 pub trait Foo {
10     type A;
11     fn boo(&self) -> Self::A;
12 }
13
14 impl Foo for isize {
15     type A = usize;
16     fn boo(&self) -> usize {
17         5
18     }
19 }
20
21 // Using a type via a function.
22 pub fn bar<T: Foo>(a: T, x: T::A) -> T::A {
23     let _: T::A = a.boo();
24     x
25 }
26
27 // Using a type via an impl.
28 trait C {
29     fn f();
30     fn g(&self) { }
31 }
32 struct B<X>(X);
33 impl<T: Foo> C for B<T> {
34     fn f() {
35         let x: T::A = panic!();
36     }
37 }
38
39 pub fn main() {
40     let z: usize = bar(2, 4);
41 }