]> git.proxmox.com Git - rustc.git/blame - src/test/ui/issues/issue-20831-debruijn.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / src / test / ui / issues / issue-20831-debruijn.rs
CommitLineData
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
6use std::cell::RefCell;
85aaf69f
SL
7use std::ops::{Shl, Shr};
8
9346a6ac 9pub trait Subscriber {
85aaf69f
SL
10 type Input;
11}
12
13pub trait Publisher<'a> {
14 type Output;
dc9dc135 15 fn subscribe(&mut self, _: Box<dyn Subscriber<Input=Self::Output> + 'a>);
85aaf69f
SL
16}
17
18pub trait Processor<'a> : Subscriber + Publisher<'a> { }
19
20impl<'a, P> Processor<'a> for P where P : Subscriber + Publisher<'a> { }
21
22struct MyStruct<'a> {
dc9dc135 23 sub: Box<dyn Subscriber<Input=u64> + 'a>
85aaf69f
SL
24}
25
26impl<'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
39fn main() {}