summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/closure-requirements/propagate-from-trait-match.rs
blob: cda781d8e263797618aeb54741b0a17188ac1ae4 (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
// Test that regions which appear only in the closure's generics (in
// this case, `'a`) are properly mapped to the creator's generics. In
// this case, the closure constrains its type parameter `T` to outlive
// the same `'a` for which it implements `Trait`, which can only be the `'a`
// from the function definition.

// compile-flags:-Zverbose

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

trait Trait<'a> {}

fn establish_relationships<T, F>(value: T, closure: F)
where
    F: FnOnce(T),
{
    closure(value)
}

fn require<'a, T>(t: T)
where
    T: Trait<'a> + 'a,
{
}

#[rustc_regions]
fn supply<'a, T>(value: T)
where
    T: Trait<'a>,
{
    establish_relationships(value, |value| {
        // This function call requires that
        //
        // (a) T: Trait<'a>
        //
        // and
        //
        // (b) T: 'a
        //
        // The latter does not hold.

        require(value);
        //~^ ERROR the parameter type `T` may not live long enough
    });
}

fn main() {}