]>
Commit | Line | Data |
---|---|---|
74b04a01 XL |
1 | // Test that we consider equal regions when checking for hidden regions in |
2 | // opaque types | |
3 | ||
4 | // check-pass | |
5 | ||
6 | // `'a == 'static` so `&'a i32` is fine as the return type | |
7 | fn equal_regions_static<'a: 'static>(x: &'a i32) -> impl Sized { | |
8 | //~^ WARNING unnecessary lifetime parameter `'a` | |
9 | x | |
10 | } | |
11 | ||
12 | // `'a == 'b` so `&'b i32` is fine as the return type | |
13 | fn equal_regions<'a: 'b, 'b: 'a>(x: &'b i32) -> impl Sized + 'a { | |
14 | let y: &'a i32 = x; | |
15 | let z: &'b i32 = y; | |
16 | x | |
17 | } | |
18 | ||
19 | // `'a == 'b` so `&'a i32` is fine as the return type | |
20 | fn equal_regions_rev<'a: 'b, 'b: 'a>(x: &'a i32) -> impl Sized + 'b { | |
21 | let y: &'a i32 = x; | |
22 | let z: &'b i32 = y; | |
23 | x | |
24 | } | |
25 | ||
26 | // `'a == 'b` so `*mut &'b i32` is fine as the return type | |
27 | fn equal_regions_inv<'a: 'b, 'b: 'a>(x: *mut &'b i32) -> impl Sized + 'a { | |
28 | let y: *mut &'a i32 = x; | |
29 | let z: *mut &'b i32 = y; | |
30 | x | |
31 | } | |
32 | ||
33 | // `'a == 'b` so `*mut &'a i32` is fine as the return type | |
34 | fn equal_regions_inv_rev<'a: 'b, 'b: 'a>(x: *mut &'a i32) -> impl Sized + 'b { | |
35 | let y: *mut &'a i32 = x; | |
36 | let z: *mut &'b i32 = y; | |
37 | x | |
38 | } | |
39 | ||
40 | // Should be able to infer `fn(&'static ())` as the return type. | |
41 | fn contravariant_lub<'a, 'b: 'a, 'c: 'a, 'd: 'b + 'c>( | |
42 | x: fn(&'b ()), | |
43 | y: fn(&'c ()), | |
44 | c: bool, | |
45 | ) -> impl Sized + 'a { | |
46 | if c { x } else { y } | |
47 | } | |
48 | ||
49 | fn main() {} |