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
7 // compile-flags:-Zborrowck=mir -Zverbose
8
9 #![allow(warnings)]
10 #![feature(rustc_attrs)]
11
12 use std::cell::Cell;
13
14 trait Anything<'a> {
15 type AssocType: 'a;
16 }
17
with_signature<'a, T, F>(cell: Cell<&'a ()>, t: T, op: F) where F: FnOnce(Cell<&'a ()>, T),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
require<'a, 'b, T>(_cell: Cell<&'a ()>, _t: T) where T: Anything<'b>, T::AssocType: 'a,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]
no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T) where T: Anything<'b>,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));
38 //~^ ERROR
39 }
40
41 #[rustc_regions]
no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T) where T: Anything<'b>, 'a: 'a,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));
48 //~^ ERROR
49 }
50
51 #[rustc_regions]
projection_outlives<'a, 'b, T>(cell: Cell<&'a ()>, t: T) where T: Anything<'b>, T::AssocType: 'a,52 fn projection_outlives<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
53 where
54 T: Anything<'b>,
55 T::AssocType: 'a,
56 {
57 // We are projecting `<T as Anything<'b>>::AssocType`, and we know
58 // that this outlives `'a` because of the where-clause.
59
60 with_signature(cell, t, |cell, t| require(cell, t));
61 }
62
63 #[rustc_regions]
elements_outlive<'a, 'b, T>(cell: Cell<&'a ()>, t: T) where T: Anything<'b>, 'b: 'a,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]
one_region<'a, T>(cell: Cell<&'a ()>, t: T) where T: Anything<'a>,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
main()84 fn main() {}
85