• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
7 use std::ops::{Shl, Shr};
8 
9 pub trait Subscriber {
10     type Input;
11 }
12 
13 pub trait Publisher<'a> {
14     type Output;
subscribe(&mut self, _: Box<dyn Subscriber<Input=Self::Output> + 'a>)15     fn subscribe(&mut self, _: Box<dyn Subscriber<Input=Self::Output> + 'a>);
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> {
23     sub: Box<dyn Subscriber<Input=u64> + 'a>
24 }
25 
26 impl<'a> Publisher<'a> for MyStruct<'a> {
27     type Output = u64;
subscribe(&mut self, t : Box<dyn Subscriber<Input=<Self as Publisher>::Output> + 'a>)28     fn subscribe(&mut self, t : Box<dyn Subscriber<Input=<Self as Publisher>::Output> + 'a>) {
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 
main()39 fn main() {}
40