rust/src/test/ui/structs-enums/object-lifetime-default-from-rptr-struct.rs

38 lines
647 B
Rust
Raw Normal View History

// run-pass
// Test that the lifetime from the enclosing `&` is "inherited"
// through the `MyBox` struct.
// pretty-expanded FIXME #23616
#![allow(dead_code)]
trait Test {
fn foo(&self) { }
}
struct SomeStruct<'a> {
2019-05-28 18:47:21 +00:00
t: &'a MyBox<dyn Test>,
u: &'a MyBox<dyn Test+'a>,
}
struct MyBox<T:?Sized> {
b: Box<T>
}
2019-05-28 18:47:21 +00:00
fn a<'a>(t: &'a MyBox<dyn Test>, mut ss: SomeStruct<'a>) {
ss.t = t;
}
2019-05-28 18:47:21 +00:00
fn b<'a>(t: &'a MyBox<dyn Test>, mut ss: SomeStruct<'a>) {
ss.u = t;
}
// see also compile-fail/object-lifetime-default-from-rptr-box-error.rs
2019-05-28 18:47:21 +00:00
fn d<'a>(t: &'a MyBox<dyn Test+'a>, mut ss: SomeStruct<'a>) {
ss.u = t;
}
fn main() {
}