]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-item-long-paths.rs
Auto merge of #75936 - sdroege:chunks-exact-construction-bounds-check, r=nagisa
[rust.git] / src / test / ui / associated-item-long-paths.rs
1 // run-pass
2
3 use std::mem::size_of;
4
5 // The main point of this test is to ensure that we can parse and resolve
6 // associated items on associated types.
7
8 trait Foo {
9     type U;
10 }
11
12 trait Bar {
13     // Note 1: Chains of associated items in a path won't type-check.
14     // Note 2: Associated consts can't depend on type parameters or `Self`,
15     // which are the only types that an associated type can be referenced on for
16     // now, so we can only test methods.
17     fn method() -> u32;
18     fn generic_method<T>() -> usize;
19 }
20
21 struct MyFoo;
22 struct MyBar;
23
24 impl Foo for MyFoo {
25     type U = MyBar;
26 }
27
28 impl Bar for MyBar {
29     fn method() -> u32 {
30         2u32
31     }
32     fn generic_method<T>() -> usize {
33         size_of::<T>()
34     }
35 }
36
37 fn foo<T>()
38     where T: Foo,
39           T::U: Bar,
40 {
41     assert_eq!(2u32, <T as Foo>::U::method());
42     assert_eq!(8usize, <T as Foo>::U::generic_method::<f64>());
43 }
44
45 fn main() {
46     foo::<MyFoo>();
47 }