2014-06-23 12:42:13 -05:00
|
|
|
trait X {
|
2015-01-08 04:54:35 -06:00
|
|
|
fn get_i(&self) -> isize;
|
2014-06-23 12:42:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
|
|
|
|
|
2014-06-23 12:42:13 -05:00
|
|
|
struct B {
|
2015-01-08 04:54:35 -06:00
|
|
|
i: isize
|
2014-06-23 12:42:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl X for B {
|
2015-01-08 04:54:35 -06:00
|
|
|
fn get_i(&self) -> isize {
|
2014-06-23 12:42:13 -05:00
|
|
|
self.i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct A<'a> {
|
2019-05-28 13:46:13 -05:00
|
|
|
p: &'a (dyn X + 'a)
|
2014-06-23 12:42:13 -05:00
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn make_a<'a>(p: &'a dyn X) -> A<'a> {
|
2014-06-23 12:42:13 -05:00
|
|
|
A { p: p }
|
|
|
|
}
|
|
|
|
|
2014-07-17 23:44:59 -05:00
|
|
|
fn make_make_a<'a>() -> A<'a> {
|
2021-08-24 19:39:40 -05:00
|
|
|
let b: Box<B> = Box::new(B { i: 1 });
|
2019-04-22 02:40:08 -05:00
|
|
|
let bb: &B = &*b;
|
|
|
|
make_a(bb) //~ ERROR cannot return value referencing local data `*b`
|
2014-06-23 12:42:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _a = make_make_a();
|
|
|
|
}
|