2014-08-28 01:46:52 +00:00
|
|
|
// Test for what happens when a type parameter `A` is closed over into
|
|
|
|
// an object. This should yield errors unless `A` (and the object)
|
|
|
|
// both have suitable bounds.
|
|
|
|
|
2020-05-20 17:58:41 +00:00
|
|
|
trait SomeTrait {
|
|
|
|
fn get(&self) -> isize;
|
|
|
|
}
|
2014-08-28 01:46:52 +00:00
|
|
|
|
2021-08-25 00:39:40 +00:00
|
|
|
|
2020-05-20 17:58:41 +00:00
|
|
|
fn make_object1<A: SomeTrait>(v: A) -> Box<dyn SomeTrait + 'static> {
|
2021-08-25 00:39:40 +00:00
|
|
|
Box::new(v) as Box<dyn SomeTrait + 'static>
|
2020-05-20 17:58:41 +00:00
|
|
|
//~^ ERROR the parameter type `A` may not live long enough
|
2014-08-28 01:46:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 17:58:41 +00:00
|
|
|
fn make_object2<'a, A: SomeTrait + 'a>(v: A) -> Box<dyn SomeTrait + 'a> {
|
2021-08-25 00:39:40 +00:00
|
|
|
Box::new(v) as Box<dyn SomeTrait + 'a>
|
2014-08-28 01:46:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 17:58:41 +00:00
|
|
|
fn make_object3<'a, 'b, A: SomeTrait + 'a>(v: A) -> Box<dyn SomeTrait + 'b> {
|
2021-08-25 00:39:40 +00:00
|
|
|
Box::new(v) as Box<dyn SomeTrait + 'b>
|
2020-05-20 17:58:41 +00:00
|
|
|
//~^ ERROR the parameter type `A` may not live long enough
|
2014-08-28 01:46:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 17:58:41 +00:00
|
|
|
fn main() {}
|