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