]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-12028.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / issues / issue-12028.rs
1 // Copyright 2014 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 an example where we fail to infer the type parameter H. This
12 // is because there is really nothing constraining it. At one time, we
13 // would infer based on the where clauses in scope, but that no longer
14 // works.
15
16 trait Hash<H> {
17     fn hash2(&self, hasher: &H) -> u64;
18 }
19
20 trait Stream {
21     fn input(&mut self, bytes: &[u8]);
22     fn result(&self) -> u64;
23 }
24
25 trait StreamHasher {
26     type S : Stream;
27     fn stream(&self) -> Self::S;
28 }
29
30 //////////////////////////////////////////////////////////////////////////////
31
32 trait StreamHash<H: StreamHasher>: Hash<H> {
33     fn input_stream(&self, stream: &mut H::S);
34 }
35
36 impl<H: StreamHasher> Hash<H> for u8 {
37     fn hash2(&self, hasher: &H) -> u64 {
38         let mut stream = hasher.stream();
39         self.input_stream(&mut stream); //~ ERROR type annotations required
40         Stream::result(&stream)
41     }
42 }
43
44 impl<H: StreamHasher> StreamHash<H> for u8 {
45     fn input_stream(&self, stream: &mut H::S) {
46         Stream::input(stream, &[*self]);
47     }
48 }
49
50 fn main() {}