rust/tests/ui/object-lifetime/object-lifetime-default-mybox.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
770 B
Rust
Raw Normal View History

// 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> {
deref(ss)
}
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>
{
a
2022-04-01 17:13:25 +00:00
//~^ ERROR lifetime may not live long enough
}
2019-05-28 18:46:13 +00:00
fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> {
load0(ss)
2022-04-01 17:13:25 +00:00
//~^ ERROR borrowed data escapes outside of function
}
fn main() {
}