]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/associated-types-projection-in-object-type.rs
a9c34a605ce163a5f2cfb842929ad6a3a7ce249d
[rust.git] / src / test / run-pass / associated-types-projection-in-object-type.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 // Corrected regression test for #20831. The original did not compile.
12 // When fixed, it revealed another problem concerning projections that
13 // appear in associated type bindings in object types, which were not
14 // being properly flagged.
15
16 use std::ops::{Shl, Shr};
17 use std::cell::RefCell;
18
19 pub trait Subscriber {
20     type Input;
21
22     fn dummy(&self) { }
23 }
24
25 pub trait Publisher<'a> {
26     type Output;
27     fn subscribe(&mut self, Box<Subscriber<Input=Self::Output> + 'a>);
28 }
29
30 pub trait Processor<'a> : Subscriber + Publisher<'a> { }
31
32 impl<'a, P> Processor<'a> for P where P : Subscriber + Publisher<'a> { }
33
34 struct MyStruct<'a> {
35     sub: Box<Subscriber<Input=u64> + 'a>
36 }
37
38 impl<'a> Publisher<'a> for MyStruct<'a> {
39     type Output = u64;
40     fn subscribe(&mut self, t : Box<Subscriber<Input=u64> + 'a>) {
41         self.sub = t;
42     }
43 }
44
45 fn main() {}