]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Test an example where we fail to infer the type parameter H. This |
2 | // is because there is really nothing constraining it. At one time, we | |
3 | // would infer based on the where clauses in scope, but that no longer | |
4 | // works. | |
5 | ||
6 | trait Hash<H> { | |
7 | fn hash2(&self, hasher: &H) -> u64; | |
8 | } | |
9 | ||
10 | trait Stream { | |
11 | fn input(&mut self, bytes: &[u8]); | |
12 | fn result(&self) -> u64; | |
13 | } | |
14 | ||
15 | trait StreamHasher { | |
16 | type S : Stream; | |
17 | fn stream(&self) -> Self::S; | |
18 | } | |
19 | ||
1a4d82fc JJ |
20 | trait StreamHash<H: StreamHasher>: Hash<H> { |
21 | fn input_stream(&self, stream: &mut H::S); | |
22 | } | |
23 | ||
24 | impl<H: StreamHasher> Hash<H> for u8 { | |
25 | fn hash2(&self, hasher: &H) -> u64 { | |
26 | let mut stream = hasher.stream(); | |
e74abb32 | 27 | self.input_stream(&mut stream); //~ ERROR type annotations needed |
1a4d82fc JJ |
28 | Stream::result(&stream) |
29 | } | |
30 | } | |
31 | ||
32 | impl<H: StreamHasher> StreamHash<H> for u8 { | |
33 | fn input_stream(&self, stream: &mut H::S) { | |
85aaf69f | 34 | Stream::input(stream, &[*self]); |
1a4d82fc JJ |
35 | } |
36 | } | |
37 | ||
38 | fn main() {} |