]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/coherence-rfc447-constrained.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / test / run-pass / coherence-rfc447-constrained.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 // check that trait matching can handle impls whose types are only
12 // constrained by a projection.
13
14 trait IsU32 {}
15 impl IsU32 for u32 {}
16
17 trait Mirror { type Image: ?Sized; }
18 impl<T: ?Sized> Mirror for T { type Image = T; }
19
20 trait Bar {}
21 impl<U: Mirror, V: Mirror<Image=L>, L: Mirror<Image=U>> Bar for V
22 where U::Image: IsU32 {}
23
24 trait Foo { fn name() -> &'static str; }
25 impl Foo for u64 { fn name() -> &'static str { "u64" } }
26 impl<T: Bar> Foo for T { fn name() -> &'static str { "Bar" }}
27
28 fn main() {
29 assert_eq!(<u64 as Foo>::name(), "u64");
30 assert_eq!(<u32 as Foo>::name(), "Bar");
31 }