]> git.proxmox.com Git - rustc.git/blob - src/test/ui/impl-trait/multiple-lifetimes/inverse-bounds.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / impl-trait / multiple-lifetimes / inverse-bounds.rs
1 // edition:2018
2 // check-pass
3
4 trait Trait<'a, 'b> {}
5 impl<T> Trait<'_, '_> for T {}
6
7 // `Invert<'a> <: Invert<'b>` if `'b: 'a`, unlike 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 Invert<'a>(fn(&'a u8));
13
14 fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Invert<'a>, b: Invert<'b>) -> impl Trait<'d, 'e>
15 where
16 'c: 'a,
17 'c: 'b,
18 'd: 'c,
19 {
20 // Representing the where clauses as a graph, where `A: B` is an
21 // edge `B -> A`:
22 //
23 // ```
24 // 'a -> 'c -> 'd
25 // ^
26 // |
27 // 'b
28 // ```
29 //
30 // Meanwhile we return a value &'0 u8 where we have the constraints:
31 //
32 // ```
33 // '0: 'a
34 // '0: 'b
35 // '0 in ['d, 'e]
36 // ```
37 //
38 // Here, ignoring the "in" constraint, the minimal choice for `'0`
39 // is `'c`, but that is not in the "in set". Still, that reduces
40 // the range of options in the "in set" to just `'d` (`'e: 'c`
41 // does not hold).
42 let p = if condition() { a } else { b };
43 p
44 }
45
46 fn condition() -> bool {
47 true
48 }
49
50 fn main() {}