summaryrefslogtreecommitdiffstats
path: root/tests/ui/regions/regions-close-over-type-parameter-multiple.rs
blob: e032a94c32fa4d6077511ac3a5c3be02cdd493c5 (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
// Various tests where we over type parameters with multiple lifetime
// bounds.

trait SomeTrait { fn get(&self) -> isize; }


fn make_object_good1<'a,'b,A:SomeTrait+'a+'b>(v: A) -> Box<dyn SomeTrait + 'a> {
    // A outlives 'a AND 'b...
    Box::new(v) as Box<dyn SomeTrait + 'a> // ...hence this type is safe.
}

fn make_object_good2<'a,'b,A:SomeTrait+'a+'b>(v: A) -> Box<dyn SomeTrait + 'b> {
    // A outlives 'a AND 'b...
    Box::new(v) as Box<dyn SomeTrait + 'b> // ...hence this type is safe.
}

fn make_object_bad<'a,'b,'c,A:SomeTrait+'a+'b>(v: A) -> Box<dyn SomeTrait + 'c> {
    // A outlives 'a AND 'b...but not 'c.
    Box::new(v) as Box<dyn SomeTrait + 'a>
    //~^ ERROR lifetime may not live long enough
}

fn main() {
}