]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/method-normalize-bounds-issue-20604.rs
5ba5d7f8d722758b55c986555756a9c402bfab15
[rust.git] / src / test / run-pass / method-normalize-bounds-issue-20604.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 // Test that we handle projection types which wind up important for
12 // resolving methods. This test was reduced from a larger example; the
13 // call to `foo()` at the end was failing to resolve because the
14 // winnowing stage of method resolution failed to handle an associated
15 // type projection.
16
17 #![feature(associated_types)]
18
19 trait Hasher {
20     type Output;
21     fn finish(&self) -> Self::Output;
22 }
23
24 trait Hash<H: Hasher> {
25     fn hash(&self, h: &mut H);
26 }
27
28 trait HashState {
29     type Wut: Hasher;
30     fn hasher(&self) -> Self::Wut;
31 }
32
33 struct SipHasher;
34 impl Hasher for SipHasher {
35     type Output = u64;
36     fn finish(&self) -> u64 { 4 }
37 }
38
39 impl Hash<SipHasher> for int {
40     fn hash(&self, h: &mut SipHasher) {}
41 }
42
43 struct SipState;
44 impl HashState for SipState {
45     type Wut = SipHasher;
46     fn hasher(&self) -> SipHasher { SipHasher }
47 }
48
49 struct Map<S> {
50     s: S,
51 }
52
53 impl<S> Map<S>
54     where S: HashState,
55           <S as HashState>::Wut: Hasher<Output=u64>,
56 {
57     fn foo<K>(&self, k: K) where K: Hash< <S as HashState>::Wut> {}
58 }
59
60 fn foo<K: Hash<SipHasher>>(map: &Map<SipState>) {
61     map.foo(22);
62 }
63
64 fn main() {}