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