|
| 1 | +// Regression test for #55756. |
| 2 | +// |
| 3 | +// In this test, the result of `self.callee` is a projection `<D as |
| 4 | +// Database<'?0>>::Guard`. As it may contain a destructor, the dropck |
| 5 | +// rules require that this type outlivess the scope of `state`. Unfortunately, |
| 6 | +// our region inference is not smart enough to figure out how to |
| 7 | +// translate a requirement like |
| 8 | +// |
| 9 | +// <D as Database<'0>>::guard: 'r |
| 10 | +// |
| 11 | +// into a requirement that `'0: 'r` -- in particular, it fails to do |
| 12 | +// so because it *also* knows that `<D as Database<'a>>::Guard: 'a` |
| 13 | +// from the trait definition. Faced with so many choices, the current |
| 14 | +// solver opts to do nothing. |
| 15 | +// |
| 16 | +// The problem we were having was that we would observe two |
| 17 | +// potentially applicable rules when trying to find bounds for `<T as |
| 18 | +// Database<'0>>::Guard`: |
| 19 | +// |
| 20 | +// ``` |
| 21 | +// <T as Database<'a>>::Guard: 'a // from the where clauses |
| 22 | +// for<'b> { <T as Database<'b>>::Guard: 'b } // from the trait definition |
| 23 | +// ``` |
| 24 | +// |
| 25 | +// Because of this, we decided to take no action to influence |
| 26 | +// inference, which means that `'0` winds up unconstrained, leading to |
| 27 | +// the ultimate error. |
| 28 | +// |
| 29 | +// compile-pass |
| 30 | + |
| 31 | +#![crate_type="lib"] |
| 32 | + |
| 33 | +pub trait Database<'a> { |
| 34 | + type Guard: 'a; |
| 35 | +} |
| 36 | + |
| 37 | +pub struct Stateful<'a, D: 'a>(&'a D); |
| 38 | + |
| 39 | +impl<'b, D: for <'a> Database<'a>> Stateful<'b, D> { |
| 40 | + pub fn callee<'a>(&'a self) -> <D as Database<'a>>::Guard { |
| 41 | + unimplemented!() |
| 42 | + } |
| 43 | + pub fn caller<'a>(&'a self) -> <D as Database<'a>>::Guard { |
| 44 | + let state = self.callee(); |
| 45 | + self.callee() |
| 46 | + } |
| 47 | +} |
0 commit comments