summaryrefslogtreecommitdiffstats
path: root/tests/ui/type-alias-impl-trait/closure_parent_substs.rs
blob: 475f4724ff28f4c4bc24a81ac1c63e2ecc61f1bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// When WF checking the hidden type in the ParamEnv of the opaque type,
// one complication arises when the hidden type is a closure/generator:
// the "parent_substs" of the type may reference lifetime parameters
// not present in the opaque type.
// These region parameters are not really useful in this check.
// So here we ignore them and replace them with fresh region variables.

// check-pass

#![feature(type_alias_impl_trait)]
#![allow(dead_code)]

// Basic test
mod test1 {
    // Hidden type = Closure['_#0r]
    type Opaque = impl Sized;

    fn define<'a: 'a>() -> Opaque {
        || {}
    }
}

// the region vars cannot both be equal to `'static` or `'empty`
mod test2 {
    trait Trait {}

    // Hidden type = Closure['a, '_#0r, '_#1r]
    // Constraints = [('_#0r: 'a), ('a: '_#1r)]
    type Opaque<'a>
    where
        &'a (): Trait,
    = impl Sized + 'a;

    fn define<'a, 'x, 'y>() -> Opaque<'a>
    where
        &'a (): Trait,
        'x: 'a,
        'a: 'y,
    {
        || {}
    }
}

// the region var cannot be equal to `'a` or `'b`
mod test3 {
    trait Trait {}

    // Hidden type = Closure['a, 'b, '_#0r]
    // Constraints = [('_#0r: 'a), ('_#0r: 'b)]
    type Opaque<'a, 'b>
    where
        (&'a (), &'b ()): Trait,
    = impl Sized + 'a + 'b;

    fn define<'a, 'b, 'x>() -> Opaque<'a, 'b>
    where
        (&'a (), &'b ()): Trait,
        'x: 'a,
        'x: 'b,
    {
        || {}
    }
}

fn main() {}