]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/ty-outlives/projection-one-region-closure.rs
Rollup merge of #106397 - compiler-errors:new-solver-impl-wc, r=lcnr
[rust.git] / tests / ui / nll / ty-outlives / projection-one-region-closure.rs
1 // Test cases where we constrain `<T as Anything<'b>>::AssocType` to
2 // outlive `'a` and there are no bounds in the trait definition of
3 // `Anything`. This means that the constraint can only be satisfied in two
4 // ways:
5 //
6 // - by ensuring that `T: 'a` and `'b: 'a`, or
7 // - by something in the where clauses.
8 //
9 // As of this writing, the where clause option does not work because
10 // of limitations in our region inferencing system (this is true both
11 // with and without NLL). See `projection_outlives`.
12 //
13 // Ensuring that both `T: 'a` and `'b: 'a` holds does work (`elements_outlive`).
14
15 // compile-flags:-Zverbose
16
17 #![allow(warnings)]
18 #![feature(rustc_attrs)]
19
20 use std::cell::Cell;
21
22 trait Anything<'a> {
23     type AssocType;
24 }
25
26 fn with_signature<'a, T, F>(cell: Cell<&'a ()>, t: T, op: F)
27 where
28     F: FnOnce(Cell<&'a ()>, T),
29 {
30     op(cell, t)
31 }
32
33 fn require<'a, 'b, T>(_cell: Cell<&'a ()>, _t: T)
34 where
35     T: Anything<'b>,
36     T::AssocType: 'a,
37 {
38 }
39
40 #[rustc_regions]
41 fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
42 where
43     T: Anything<'b>,
44 {
45     with_signature(cell, t, |cell, t| require(cell, t));
46     //~^ ERROR the parameter type `T` may not live long enough
47     //~| ERROR
48 }
49
50 #[rustc_regions]
51 fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
52 where
53     T: Anything<'b>,
54     'a: 'a,
55 {
56     with_signature(cell, t, |cell, t| require(cell, t));
57     //~^ ERROR the parameter type `T` may not live long enough
58     //~| ERROR
59 }
60
61 #[rustc_regions]
62 fn projection_outlives<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
63 where
64     T: Anything<'b>,
65     T::AssocType: 'a,
66 {
67     // We are projecting `<T as Anything<'b>>::AssocType`, and we know
68     // that this outlives `'a` because of the where-clause.
69
70     with_signature(cell, t, |cell, t| require(cell, t));
71 }
72
73 #[rustc_regions]
74 fn elements_outlive<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
75 where
76     T: Anything<'b>,
77     T: 'a,
78     'b: 'a,
79 {
80     with_signature(cell, t, |cell, t| require(cell, t));
81 }
82
83 fn main() {}