mirror of
https://github.com/rust-lang/rust
synced 2024-09-05 16:57:03 +00:00
25 lines
723 B
Rust
25 lines
723 B
Rust
// 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.
|
|
|
|
trait SomeTrait {
|
|
fn get(&self) -> isize;
|
|
}
|
|
|
|
|
|
fn make_object1<A: SomeTrait>(v: A) -> Box<dyn SomeTrait + 'static> {
|
|
Box::new(v) as Box<dyn SomeTrait + 'static>
|
|
//~^ ERROR the parameter type `A` may not live long enough
|
|
}
|
|
|
|
fn make_object2<'a, A: SomeTrait + 'a>(v: A) -> Box<dyn SomeTrait + 'a> {
|
|
Box::new(v) as Box<dyn SomeTrait + 'a>
|
|
}
|
|
|
|
fn make_object3<'a, 'b, A: SomeTrait + 'a>(v: A) -> Box<dyn SomeTrait + 'b> {
|
|
Box::new(v) as Box<dyn SomeTrait + 'b>
|
|
//~^ ERROR the parameter type `A` may not live long enough
|
|
}
|
|
|
|
fn main() {}
|