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