use core::cell::Cell; use selfref::Holder; use selfref::NewWith; use selfref::opaque; mod bad { use super::*; use std::rc::Rc; struct Foo<'a> { x: String, y: Rc>, } struct FooOpaque; opaque! { impl Opaque for FooOpaque { type Kind<'a> = Foo<'a>; } } pub fn test() { let rc = Rc::new(Cell::new("")); struct FooBuilder<'b>(Rc>); impl<'k, 'b> NewWith<'k, FooOpaque> for FooBuilder<'b> { fn new_with<'a>(self) -> Foo<'a> where 'k: 'a { Foo { x: "Hello".to_owned(), y: self.0, } } } let x = Holder::new_with(FooBuilder(rc.clone())); let x = Box::pin(x); x.as_ref().operate_in(|foo| { let foo = foo.get_ref(); foo.y.set(&foo.x); }); dbg!(&rc); drop(x); dbg!(&rc); } } fn main() { bad::test(); }