]>
Commit | Line | Data |
---|---|---|
85aaf69f SL |
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 | // Regression test for #20831: debruijn index account was thrown off | |
12 | // by the (anonymous) lifetime in `<Self as Publisher>::Output` | |
13 | // below. Note that changing to a named lifetime made the problem go | |
14 | // away. | |
15 | ||
16 | use std::cell::RefCell; | |
85aaf69f SL |
17 | use std::ops::{Shl, Shr}; |
18 | ||
9346a6ac | 19 | pub trait Subscriber { |
85aaf69f SL |
20 | type Input; |
21 | } | |
22 | ||
23 | pub trait Publisher<'a> { | |
24 | type Output; | |
041b39d2 | 25 | fn subscribe(&mut self, _: Box<Subscriber<Input=Self::Output> + 'a>); |
85aaf69f SL |
26 | } |
27 | ||
28 | pub trait Processor<'a> : Subscriber + Publisher<'a> { } | |
29 | ||
30 | impl<'a, P> Processor<'a> for P where P : Subscriber + Publisher<'a> { } | |
31 | ||
32 | struct MyStruct<'a> { | |
33 | sub: Box<Subscriber<Input=u64> + 'a> | |
34 | } | |
35 | ||
36 | impl<'a> Publisher<'a> for MyStruct<'a> { | |
37 | type Output = u64; | |
38 | fn subscribe(&mut self, t : Box<Subscriber<Input=<Self as Publisher>::Output> + 'a>) { | |
39 | // Not obvious, but there is an implicit lifetime here -------^ | |
40 | //~^^ ERROR cannot infer | |
9cc50fc6 | 41 | //~| ERROR cannot infer |
85aaf69f SL |
42 | // |
43 | // The fact that `Publisher` is using an implicit lifetime is | |
44 | // what was causing the debruijn accounting to be off, so | |
45 | // leave it that way! | |
46 | self.sub = t; | |
47 | } | |
48 | } | |
49 | ||
50 | fn main() {} |