]> git.lizzy.rs Git - rust.git/blob - tests/ui/associated-types/associated-types-projection-from-known-type-in-impl.rs
Rollup merge of #106441 - mllken:abstract-socket-noref, r=joshtriplett
[rust.git] / tests / ui / associated-types / associated-types-projection-from-known-type-in-impl.rs
1 // run-pass
2 // Test where the impl self type uses a projection from a constant type.
3
4
5 trait Int
6 {
7     type T;
8
9     fn dummy(&self) { }
10 }
11
12 trait NonZero
13 {
14     fn non_zero(self) -> bool;
15 }
16
17 impl Int for i32 { type T = i32; }
18 impl Int for i64 { type T = i64; }
19 impl Int for u32 { type T = u32; }
20 impl Int for u64 { type T = u64; }
21
22 impl NonZero for <i32 as Int>::T { fn non_zero(self) -> bool { self != 0 } }
23 impl NonZero for <i64 as Int>::T { fn non_zero(self) -> bool { self != 0 } }
24 impl NonZero for <u32 as Int>::T { fn non_zero(self) -> bool { self != 0 } }
25 impl NonZero for <u64 as Int>::T { fn non_zero(self) -> bool { self != 0 } }
26
27 fn main ()
28 {
29     assert!(NonZero::non_zero(22_i32));
30     assert!(NonZero::non_zero(22_i64));
31     assert!(NonZero::non_zero(22_u32));
32     assert!(NonZero::non_zero(22_u64));
33
34     assert!(!NonZero::non_zero(0_i32));
35     assert!(!NonZero::non_zero(0_i64));
36     assert!(!NonZero::non_zero(0_u32));
37     assert!(!NonZero::non_zero(0_u64));
38 }