2014-06-24 21:51:12 +00:00
|
|
|
// Issue #12470.
|
|
|
|
|
|
|
|
trait X {
|
2015-01-08 10:54:35 +00:00
|
|
|
fn get_i(&self) -> isize;
|
2014-06-24 21:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct B {
|
2015-01-08 10:54:35 +00:00
|
|
|
i: isize
|
2014-06-24 21:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl X for B {
|
2015-01-08 10:54:35 +00:00
|
|
|
fn get_i(&self) -> isize {
|
2014-06-24 21:51:12 +00:00
|
|
|
self.i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for B {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
println!("drop");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct A<'r> {
|
2019-05-28 18:46:13 +00:00
|
|
|
p: &'r (dyn X + 'r)
|
2014-06-24 21:51:12 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 18:46:13 +00:00
|
|
|
fn make_a(p: &dyn X) -> A {
|
2014-06-24 21:51:12 +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 {
|
2014-06-24 21:51:12 +00:00
|
|
|
i: 1,
|
2021-08-25 00:39:40 +00:00
|
|
|
});
|
|
|
|
|
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-24 21:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let a = make_make_a();
|
|
|
|
println!("{}", a.p.get_i());
|
|
|
|
}
|