2015-02-12 08:37:52 -06: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 13:46:13 -05:00
|
|
|
fn load0(ss: &MyBox<dyn SomeTrait>) -> MyBox<dyn SomeTrait> {
|
2015-07-14 18:36:15 -05:00
|
|
|
deref(ss)
|
2015-02-12 08:37:52 -06:00
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>,
|
|
|
|
b: &'b MyBox<dyn SomeTrait>)
|
|
|
|
-> &'b MyBox<dyn SomeTrait>
|
2015-02-12 08:37:52 -06:00
|
|
|
{
|
2022-05-21 13:45:57 -05:00
|
|
|
a
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR lifetime may not live long enough
|
2015-02-12 08:37:52 -06:00
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> {
|
2022-05-21 13:45:57 -05:00
|
|
|
load0(ss)
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR borrowed data escapes outside of function
|
2015-06-17 13:11:58 -05:00
|
|
|
}
|
|
|
|
|
2015-02-12 08:37:52 -06:00
|
|
|
fn main() {
|
|
|
|
}
|