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
8 // compile-flags:-Zverbose
11 #![feature(rustc_attrs)]
15 trait Anything<'a, 'b> {
16 type AssocType: 'a + 'b;
19 fn with_signature<'a, T, F>(cell: Cell<&'a ()>, t: T, op: F)
21 F: FnOnce(Cell<&'a ()>, T),
26 fn require<'a, 'b, 'c, T>(_cell: Cell<&'a ()>, _t: T)
34 fn no_relationships_late<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
38 with_signature(cell, t, |cell, t| require(cell, t));
39 //~^ ERROR may not live long enough
43 fn no_relationships_early<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
48 with_signature(cell, t, |cell, t| require(cell, t));
49 //~^ ERROR may not live long enough
53 fn projection_outlives<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
58 // We are projecting `<T as Anything<'b>>::AssocType`, and we know
59 // that this outlives `'a` because of the where-clause.
61 with_signature(cell, t, |cell, t| require(cell, t));
65 fn elements_outlive1<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
70 with_signature(cell, t, |cell, t| require(cell, t));
74 fn elements_outlive2<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
79 with_signature(cell, t, |cell, t| require(cell, t));
83 fn two_regions<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
87 with_signature(cell, t, |cell, t| require(cell, t));
88 //~^ ERROR lifetime may not live long enough
92 fn two_regions_outlive<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
97 with_signature(cell, t, |cell, t| require(cell, t));
101 fn one_region<'a, T>(cell: Cell<&'a ()>, t: T)
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
109 with_signature(cell, t, |cell, t| require(cell, t));