Files
rust/src/test/ui/object-lifetime/object-lifetime-default-mybox.rs

44 lines
948 B
Rust
Raw Normal View History

// ignore-compare-mode-nll
// revisions: base nll
// [nll]compile-flags: -Zborrowck=mir
// 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 14:46:13 -04:00
fn load0(ss: &MyBox<dyn SomeTrait>) -> MyBox<dyn SomeTrait> {
deref(ss)
}
2019-05-28 14:46:13 -04:00
fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>,
b: &'b MyBox<dyn SomeTrait>)
-> &'b MyBox<dyn SomeTrait>
{
a
//[base]~^ ERROR lifetime mismatch
//[nll]~^^ ERROR lifetime may not live long enough
}
2019-05-28 14:46:13 -04:00
fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> {
load0(ss)
//[base]~^ ERROR mismatched types
//[nll]~^^ ERROR borrowed data escapes outside of function
}
fn main() {
}