]> git.lizzy.rs Git - rust.git/blob - src/test/ui/specialization/specialization-translate-projections.rs
fcccb67902e58a92b95e1e86bfc369df809b404c
[rust.git] / src / test / ui / specialization / specialization-translate-projections.rs
1 // run-pass
2
3 // Ensure that provided items are inherited properly even when impls vary in
4 // type parameters *and* rely on projections.
5
6 #![feature(specialization)]
7
8 use std::convert::Into;
9
10 trait Trait {
11     fn to_u8(&self) -> u8;
12 }
13 trait WithAssoc {
14     type Item;
15     fn to_item(&self) -> Self::Item;
16 }
17
18 impl<T, U> Trait for T where T: WithAssoc<Item=U>, U: Into<u8> {
19     fn to_u8(&self) -> u8 {
20         self.to_item().into()
21     }
22 }
23
24 impl WithAssoc for u8 {
25     type Item = u8;
26     fn to_item(&self) -> u8 { *self }
27 }
28
29 impl Trait for u8 {}
30
31 fn main() {
32     assert!(3u8.to_u8() == 3u8);
33 }