]> git.proxmox.com Git - rustc.git/blob - src/test/ui/type-alias-impl-trait/closure_wf_outlives.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / type-alias-impl-trait / closure_wf_outlives.rs
1 // If the hidden type is a closure, we require the "outlives" bounds that appear on the
2 // defining site to also appear on the opaque type.
3 //
4 // It's not clear if this is the desired behavior but at least
5 // it's consistent and has no back-compat risk.
6
7 // check-fail
8
9 #![feature(type_alias_impl_trait)]
10 #![allow(dead_code)]
11
12 // requires `'a: 'b` bound
13 mod test1 {
14 type Opaque<'a, 'b> = impl Sized + 'a + 'b;
15 //~^ ERROR lifetime bound not satisfied
16
17 fn define<'a, 'b>() -> Opaque<'a, 'b>
18 where
19 'a: 'b,
20 {
21 || {}
22 }
23 }
24
25 // Same as the above but through indirection `'x`
26 mod test2 {
27 type Opaque<'a, 'b> = impl Sized + 'a + 'b;
28 //~^ ERROR cannot infer an appropriate lifetime
29
30 fn define<'a, 'b, 'x>() -> Opaque<'a, 'b>
31 where
32 'a: 'x,
33 'x: 'b,
34 {
35 || {}
36 }
37 }
38
39 // fixed version of the above
40 mod test2_fixed {
41 type Opaque<'a: 'b, 'b> = impl Sized + 'a + 'b;
42
43 fn define<'a, 'b, 'x>() -> Opaque<'a, 'b>
44 where
45 'a: 'x,
46 'x: 'b,
47 {
48 || {}
49 }
50 }
51
52 // requires `T: 'static`
53 mod test3 {
54 type Opaque<T> = impl Sized;
55 //~^ ERROR the parameter type `T` may not live long enough
56
57 fn define<T>() -> Opaque<T>
58 where
59 T: 'static,
60 {
61 || {}
62 }
63 }
64
65 fn main() {}