use std::cell::RefCell;
struct StructWithLifetime<'a> {
_a: &'a i32,
}
impl Drop for StructWithLifetime<'_> {
fn drop(&mut self) {}
}
struct Manager<'a> {
a: RefCell<StructWithLifetime<'a>>,
}
struct Weird<'a> {
manager: &'a Manager<'a>,
}
fn main() {
let manager = Manager {
a: RefCell::new(StructWithLifetime { _a: &0 }),
};
let weird = Weird { manager: &manager };
}
Removing the drop
, replacing RefCell
with Box
, or introducing two lifetimes for Weird
can all resolve the issue. However, I don't understand the underlying reason. Can someone explain?