]> git.lizzy.rs Git - rust.git/blob - tests/ui/type-alias-impl-trait/closure_parent_substs.rs
Auto merge of #106458 - albertlarsan68:move-tests, r=jyn514
[rust.git] / tests / ui / type-alias-impl-trait / closure_parent_substs.rs
1 // When WF checking the hidden type in the ParamEnv of the opaque type,
2 // one complication arises when the hidden type is a closure/generator:
3 // the "parent_substs" of the type may reference lifetime parameters
4 // not present in the opaque type.
5 // These region parameters are not really useful in this check.
6 // So here we ignore them and replace them with fresh region variables.
7
8 // check-pass
9
10 #![feature(type_alias_impl_trait)]
11 #![allow(dead_code)]
12
13 // Basic test
14 mod test1 {
15     // Hidden type = Closure['_#0r]
16     type Opaque = impl Sized;
17
18     fn define<'a: 'a>() -> Opaque {
19         || {}
20     }
21 }
22
23 // the region vars cannot both be equal to `'static` or `'empty`
24 mod test2 {
25     trait Trait {}
26
27     // Hidden type = Closure['a, '_#0r, '_#1r]
28     // Constraints = [('_#0r: 'a), ('a: '_#1r)]
29     type Opaque<'a>
30     where
31         &'a (): Trait,
32     = impl Sized + 'a;
33
34     fn define<'a, 'x, 'y>() -> Opaque<'a>
35     where
36         &'a (): Trait,
37         'x: 'a,
38         'a: 'y,
39     {
40         || {}
41     }
42 }
43
44 // the region var cannot be equal to `'a` or `'b`
45 mod test3 {
46     trait Trait {}
47
48     // Hidden type = Closure['a, 'b, '_#0r]
49     // Constraints = [('_#0r: 'a), ('_#0r: 'b)]
50     type Opaque<'a, 'b>
51     where
52         (&'a (), &'b ()): Trait,
53     = impl Sized + 'a + 'b;
54
55     fn define<'a, 'b, 'x>() -> Opaque<'a, 'b>
56     where
57         (&'a (), &'b ()): Trait,
58         'x: 'a,
59         'x: 'b,
60     {
61         || {}
62     }
63 }
64
65 fn main() {}