]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.rs
Do not rename bound variables when verbose-printing binders.
[rust.git] / src / test / ui / nll / ty-outlives / projection-two-region-trait-bound-closure.rs
1 // Test cases where we constrain `<T as Anything<'a, 'b>>::AssocType`
2 // to outlive `'a` and there are two bounds in the trait definition of
3 // `Anything` -- i.e., we know that `AssocType` outlives `'a` and
4 // `'b`. In this case, it's not clear what is the best way to satisfy
5 // the trait bound, and hence we propagate it to the caller as a type
6 // test.
7
8 // compile-flags:-Zverbose
9
10 #![allow(warnings)]
11 #![feature(rustc_attrs)]
12
13 use std::cell::Cell;
14
15 trait Anything<'a, 'b> {
16     type AssocType: 'a + 'b;
17 }
18
19 fn with_signature<'a, T, F>(cell: Cell<&'a ()>, t: T, op: F)
20 where
21     F: FnOnce(Cell<&'a ()>, T),
22 {
23     op(cell, t)
24 }
25
26 fn require<'a, 'b, 'c, T>(_cell: Cell<&'a ()>, _t: T)
27 where
28     T: Anything<'b, 'c>,
29     T::AssocType: 'a,
30 {
31 }
32
33 #[rustc_regions]
34 fn no_relationships_late<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
35 where
36     T: Anything<'b, 'c>,
37 {
38     with_signature(cell, t, |cell, t| require(cell, t));
39     //~^ ERROR may not live long enough
40 }
41
42 #[rustc_regions]
43 fn no_relationships_early<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
44 where
45     T: Anything<'b, 'c>,
46     'a: 'a,
47 {
48     with_signature(cell, t, |cell, t| require(cell, t));
49     //~^ ERROR may not live long enough
50 }
51
52 #[rustc_regions]
53 fn projection_outlives<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
54 where
55     T: Anything<'b, 'c>,
56     T::AssocType: 'a,
57 {
58     // We are projecting `<T as Anything<'b>>::AssocType`, and we know
59     // that this outlives `'a` because of the where-clause.
60
61     with_signature(cell, t, |cell, t| require(cell, t));
62 }
63
64 #[rustc_regions]
65 fn elements_outlive1<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
66 where
67     T: Anything<'b, 'c>,
68     'b: 'a,
69 {
70     with_signature(cell, t, |cell, t| require(cell, t));
71 }
72
73 #[rustc_regions]
74 fn elements_outlive2<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
75 where
76     T: Anything<'b, 'c>,
77     'c: 'a,
78 {
79     with_signature(cell, t, |cell, t| require(cell, t));
80 }
81
82 #[rustc_regions]
83 fn two_regions<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
84 where
85     T: Anything<'b, 'b>,
86 {
87     with_signature(cell, t, |cell, t| require(cell, t));
88     //~^ ERROR lifetime may not live long enough
89 }
90
91 #[rustc_regions]
92 fn two_regions_outlive<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
93 where
94     T: Anything<'b, 'b>,
95     'b: 'a,
96 {
97     with_signature(cell, t, |cell, t| require(cell, t));
98 }
99
100 #[rustc_regions]
101 fn one_region<'a, T>(cell: Cell<&'a ()>, t: T)
102 where
103     T: Anything<'a, 'a>,
104 {
105     // Note that in this case the closure still propagates an external
106     // requirement between two variables in its signature, but the
107     // creator maps both those two region variables to `'a` on its
108     // side.
109     with_signature(cell, t, |cell, t| require(cell, t));
110 }
111
112 fn main() {}