]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/specialization/specialization-translate-projections.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / run-pass / specialization / specialization-translate-projections.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Ensure that provided items are inherited properly even when impls vary in
12 // type parameters *and* rely on projections.
13
14 #![feature(specialization)]
15
16 use std::convert::Into;
17
18 trait Trait {
19 fn to_u8(&self) -> u8;
20 }
21 trait WithAssoc {
22 type Item;
23 fn to_item(&self) -> Self::Item;
24 }
25
26 impl<T, U> Trait for T where T: WithAssoc<Item=U>, U: Into<u8> {
27 fn to_u8(&self) -> u8 {
28 self.to_item().into()
29 }
30 }
31
32 impl WithAssoc for u8 {
33 type Item = u8;
34 fn to_item(&self) -> u8 { *self }
35 }
36
37 impl Trait for u8 {}
38
39 fn main() {
40 assert!(3u8.to_u8() == 3u8);
41 }