]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.rs
Check that RPITs constrained by a recursive call in a closure are compatible
[rust.git] / src / test / ui / impl-trait / multiple-lifetimes / ordinary-bounds-unsuited.rs
1 // edition:2018
2
3 trait Trait<'a, 'b> {}
4 impl<T> Trait<'_, '_> for T {}
5
6 // `Ordinary<'a> <: Ordinary<'b>` if `'a: 'b`, as with most types.
7 //
8 // I am purposefully avoiding the terms co- and contra-variant because
9 // their application to regions depends on how you interpreted Rust
10 // regions. -nikomatsakis
11 struct Ordinary<'a>(&'a u8);
12
13 // Here we need something outlived by `'a` *and* outlived by `'b`, but
14 // we can only name `'a` and `'b` (and neither suits). So we get an
15 // error. Somewhat unfortunate, though, since the caller would have to
16 // consider the loans for both `'a` and `'b` alive.
17
18 fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b>
19 {
20     // We return a value:
21     //
22     // ```
23     // 'a: '0
24     // 'b: '1
25     // '0 in ['a, 'b]
26     // ```
27     //
28     // but we don't have it.
29     //
30     // We are forced to pick that '0 = 'e, because only 'e is outlived by *both* 'a and 'b.
31     if condition() { a } else { b }
32     //~^ ERROR hidden type for `impl Trait` captures lifetime that does not appear in bounds
33 }
34
35 fn condition() -> bool {
36     true
37 }
38
39 fn main() {}