]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.rs
Rollup merge of #106397 - compiler-errors:new-solver-impl-wc, r=lcnr
[rust.git] / tests / ui / nll / ty-outlives / ty-param-closure-outlives-from-return-type.rs
1 // compile-flags:-Zverbose
2
3 #![allow(warnings)]
4 #![feature(rustc_attrs)]
5
6 use std::fmt::Debug;
7
8 fn with_signature<'a, T, F>(x: Box<T>, op: F) -> Box<dyn Debug + 'a>
9     where F: FnOnce(Box<T>) -> Box<dyn Debug + 'a>
10 {
11     op(x)
12 }
13
14 #[rustc_regions]
15 fn no_region<'a, T>(x: Box<T>) -> Box<dyn Debug + 'a>
16 where
17     T: Debug,
18 {
19     // Here, the closure winds up being required to prove that `T:
20     // 'a`.  In principle, it could know that, except that it is
21     // type-checked in a fully generic way, and hence it winds up with
22     // a propagated requirement that `T: '_#2`, where `'_#2` appears
23     // in the return type. The caller makes the mapping from `'_#2` to
24     // `'a` (and subsequently reports an error).
25
26     with_signature(x, |y| y)
27     //~^ ERROR the parameter type `T` may not live long enough
28 }
29
30 fn correct_region<'a, T>(x: Box<T>) -> Box<Debug + 'a>
31 where
32     T: 'a + Debug,
33 {
34     x
35 }
36
37 fn wrong_region<'a, 'b, T>(x: Box<T>) -> Box<Debug + 'a>
38 where
39     T: 'b + Debug,
40 {
41     x
42     //~^ ERROR the parameter type `T` may not live long enough
43 }
44
45 fn outlives_region<'a, 'b, T>(x: Box<T>) -> Box<Debug + 'a>
46 where
47     T: 'b + Debug,
48     'b: 'a,
49 {
50     x
51 }
52
53 fn main() {}