]>
Commit | Line | Data |
---|---|---|
ff7c6d11 XL |
1 | // Test cases where we constrain `<T as Anything<'b>>::AssocType` to |
2 | // outlive `'a` and there is a unique bound in the trait definition of | |
3 | // `Anything` -- i.e., we know that `AssocType` outlives `'b`. In this | |
4 | // case, the best way to satisfy the trait bound is to show that `'b: | |
5 | // 'a`, which can be done in various ways. | |
6 | ||
923072b8 | 7 | // compile-flags:-Zverbose |
ff7c6d11 XL |
8 | |
9 | #![allow(warnings)] | |
ff7c6d11 XL |
10 | #![feature(rustc_attrs)] |
11 | ||
12 | use std::cell::Cell; | |
13 | ||
14 | trait Anything<'a> { | |
15 | type AssocType: 'a; | |
16 | } | |
17 | ||
18 | fn with_signature<'a, T, F>(cell: Cell<&'a ()>, t: T, op: F) | |
19 | where | |
20 | F: FnOnce(Cell<&'a ()>, T), | |
21 | { | |
22 | op(cell, t) | |
23 | } | |
24 | ||
25 | fn require<'a, 'b, T>(_cell: Cell<&'a ()>, _t: T) | |
26 | where | |
27 | T: Anything<'b>, | |
28 | T::AssocType: 'a, | |
29 | { | |
30 | } | |
31 | ||
32 | #[rustc_regions] | |
33 | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T) | |
34 | where | |
35 | T: Anything<'b>, | |
36 | { | |
37 | with_signature(cell, t, |cell, t| require(cell, t)); | |
b7449926 | 38 | //~^ ERROR |
ff7c6d11 XL |
39 | } |
40 | ||
41 | #[rustc_regions] | |
42 | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T) | |
43 | where | |
44 | T: Anything<'b>, | |
45 | 'a: 'a, | |
46 | { | |
47 | with_signature(cell, t, |cell, t| require(cell, t)); | |
b7449926 | 48 | //~^ ERROR |
ff7c6d11 XL |
49 | } |
50 | ||
51 | #[rustc_regions] | |
52 | fn projection_outlives<'a, 'b, T>(cell: Cell<&'a ()>, t: T) | |
53 | where | |
54 | T: Anything<'b>, | |
55 | T::AssocType: 'a, | |
56 | { | |
0bf4aa26 XL |
57 | // We are projecting `<T as Anything<'b>>::AssocType`, and we know |
58 | // that this outlives `'a` because of the where-clause. | |
ff7c6d11 XL |
59 | |
60 | with_signature(cell, t, |cell, t| require(cell, t)); | |
ff7c6d11 XL |
61 | } |
62 | ||
63 | #[rustc_regions] | |
64 | fn elements_outlive<'a, 'b, T>(cell: Cell<&'a ()>, t: T) | |
65 | where | |
66 | T: Anything<'b>, | |
67 | 'b: 'a, | |
68 | { | |
69 | with_signature(cell, t, |cell, t| require(cell, t)); | |
70 | } | |
71 | ||
72 | #[rustc_regions] | |
73 | fn one_region<'a, T>(cell: Cell<&'a ()>, t: T) | |
74 | where | |
75 | T: Anything<'a>, | |
76 | { | |
77 | // Note that in this case the closure still propagates an external | |
78 | // requirement between two variables in its signature, but the | |
79 | // creator maps both those two region variables to `'a` on its | |
80 | // side. | |
81 | with_signature(cell, t, |cell, t| require(cell, t)); | |
82 | } | |
83 | ||
84 | fn main() {} |