summaryrefslogtreecommitdiffstats
path: root/tests/ui/regions/region-bounds-on-objects-and-type-parameters.rs
blob: 40d2b740b430331c7d273bd1d243629dff0b35be (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
// Test related to when a region bound is required to be specified.

trait IsStatic : 'static { }
trait IsSend : Send { }
trait Is<'a> : 'a { }
trait Is2<'a> : 'a { }
trait SomeTrait { }

// Bounds on object types:

struct Foo<'a,'b,'c> { //~ ERROR parameter `'c` is never used
    // All of these are ok, because we can derive exactly one bound:
    a: Box<dyn IsStatic>,
    b: Box<dyn Is<'static>>,
    c: Box<dyn Is<'a>>,
    d: Box<dyn IsSend>,
    e: Box<dyn Is<'a>+Send>, // we can derive two bounds, but one is 'static, so ok
    f: Box<dyn SomeTrait>,   // OK, defaults to 'static due to RFC 599.
    g: Box<dyn SomeTrait+'a>,

    z: Box<dyn Is<'a>+'b+'c>,
    //~^ ERROR only a single explicit lifetime bound is permitted
    //~| ERROR lifetime bound not satisfied
}

fn test<
    'a,
    'b,
    A:IsStatic,
    B:Is<'a>+Is2<'b>, // OK in a parameter, but not an object type.
    C:'b+Is<'a>+Is2<'b>,
    D:Is<'a>+Is2<'static>,
    E:'a+'b           // OK in a parameter, but not an object type.
>() { }

fn main() { }