2015-02-12 14:37:52 +00:00
|
|
|
// Test a "pass-through" object-lifetime-default that produces errors.
|
|
|
|
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
trait SomeTrait {
|
|
|
|
fn dummy(&self) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MyBox<T:?Sized> {
|
|
|
|
r: Box<T>
|
|
|
|
}
|
|
|
|
|
|
|
|
fn deref<T>(ss: &T) -> T {
|
|
|
|
// produces the type of a deref without worrying about whether a
|
|
|
|
// move out would actually be legal
|
|
|
|
loop { }
|
|
|
|
}
|
|
|
|
|
2019-05-28 18:46:13 +00:00
|
|
|
fn load0(ss: &MyBox<dyn SomeTrait>) -> MyBox<dyn SomeTrait> {
|
2015-07-14 23:36:15 +00:00
|
|
|
deref(ss)
|
2015-02-12 14:37:52 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 18:46:13 +00:00
|
|
|
fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>,
|
|
|
|
b: &'b MyBox<dyn SomeTrait>)
|
|
|
|
-> &'b MyBox<dyn SomeTrait>
|
2015-02-12 14:37:52 +00:00
|
|
|
{
|
2022-05-21 18:45:57 +00:00
|
|
|
a
|
2022-04-01 17:13:25 +00:00
|
|
|
//~^ ERROR lifetime may not live long enough
|
2015-02-12 14:37:52 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 18:46:13 +00:00
|
|
|
fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> {
|
2022-05-21 18:45:57 +00:00
|
|
|
load0(ss)
|
2022-04-01 17:13:25 +00:00
|
|
|
//~^ ERROR borrowed data escapes outside of function
|
2015-06-17 18:11:58 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 14:37:52 +00:00
|
|
|
fn main() {
|
|
|
|
}
|