]> git.lizzy.rs Git - rust.git/blob - tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-other.rs
Rollup merge of #106661 - mjguzik:linux_statx, r=Mark-Simulacrum
[rust.git] / tests / ui / impl-trait / multiple-lifetimes / ordinary-bounds-pick-other.rs
1 // edition:2018
2 // build-pass (FIXME(62277): could be check-pass?)
3
4 trait Trait<'a, 'b> {}
5 impl<T> Trait<'_, '_> for T {}
6
7 // `Ordinary<'a> <: Ordinary<'b>` if `'a: 'b`, as with most types.
8 //
9 // I am purposefully avoiding the terms co- and contra-variant because
10 // their application to regions depends on how you interpreted Rust
11 // regions. -nikomatsakis
12 struct Ordinary<'a>(&'a u8);
13
14 // Here we wind up selecting `'e` in the hidden type because
15 // we need something outlived by both `'a` and `'b` and only `'e` applies.
16
17 fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e>
18 where
19     'a: 'e,
20     'b: 'e,
21     'a: 'd,
22 {
23     // We return a value:
24     //
25     // ```
26     // 'a: '0
27     // 'b: '1
28     // '0 in ['d, 'e]
29     // ```
30     //
31     // but we don't have it.
32     //
33     // We are forced to pick that '0 = 'e, because only 'e is outlived by *both* 'a and 'b.
34     let p = if condition() { a } else { b };
35     p
36 }
37
38 fn condition() -> bool {
39     true
40 }
41
42 fn main() {}