]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Various tests where we over type parameters with multiple lifetime |
2 | // bounds. | |
3 | ||
4 | trait SomeTrait { fn get(&self) -> isize; } | |
5 | ||
c295e0f8 | 6 | |
dc9dc135 | 7 | fn make_object_good1<'a,'b,A:SomeTrait+'a+'b>(v: A) -> Box<dyn SomeTrait + 'a> { |
1a4d82fc | 8 | // A outlives 'a AND 'b... |
c295e0f8 | 9 | Box::new(v) as Box<dyn SomeTrait + 'a> // ...hence this type is safe. |
1a4d82fc JJ |
10 | } |
11 | ||
dc9dc135 | 12 | fn make_object_good2<'a,'b,A:SomeTrait+'a+'b>(v: A) -> Box<dyn SomeTrait + 'b> { |
1a4d82fc | 13 | // A outlives 'a AND 'b... |
c295e0f8 | 14 | Box::new(v) as Box<dyn SomeTrait + 'b> // ...hence this type is safe. |
1a4d82fc JJ |
15 | } |
16 | ||
dc9dc135 | 17 | fn make_object_bad<'a,'b,'c,A:SomeTrait+'a+'b>(v: A) -> Box<dyn SomeTrait + 'c> { |
1a4d82fc | 18 | // A outlives 'a AND 'b...but not 'c. |
04454e1e | 19 | Box::new(v) as Box<dyn SomeTrait + 'a> |
923072b8 | 20 | //~^ ERROR lifetime may not live long enough |
1a4d82fc JJ |
21 | } |
22 | ||
23 | fn main() { | |
24 | } |