| 1 |
#[lang = "sized"] |
| 2 |
pub trait Sized {} |
| 3 |
|
| 4 |
trait Hash<H> { |
| 5 |
fn hash2(&self, hasher: &H) -> u64; |
| 6 |
} |
| 7 |
|
| 8 |
trait Stream { |
| 9 |
fn input(&mut self, bytes: &[u8]); |
| 10 |
fn result(&self) -> u64; |
| 11 |
} |
| 12 |
|
| 13 |
trait StreamHasher { |
| 14 |
type S: Stream; |
| 15 |
fn stream(&self) -> Self::S; |
| 16 |
} |
| 17 |
|
| 18 |
////////////////////////////////////////////////////////////////////////////// |
| 19 |
|
| 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(); |
| 27 |
self.input_stream(&mut stream); |
| 28 |
// { dg-error "type annotations needed" "" { target *-*-* } .-1 } |
| 29 |
Stream::result(&stream) |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
impl<H: StreamHasher> StreamHash<H> for u8 { |
| 34 |
fn input_stream(&self, stream: &mut H::S) { |
| 35 |
Stream::input(stream, &[*self]); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
fn main() {} |