Spot the bug in the Rc node graph

from Smart pointers
Rust 1.98 intermediate 4 min 1 issue to find

Find why these nodes can remain allocated after external handles are dropped.

Rust
use std::cell::RefCell;
use std::rc::Rc;

struct Node {
    parent: RefCell<Option<Rc<Node>>>,
    children: RefCell<Vec<Rc<Node>>>,
}

fn attach(parent: &Rc<Node>, child: &Rc<Node>) {
    *child.parent.borrow_mut() = Some(Rc::clone(parent));
    parent.children.borrow_mut().push(Rc::clone(child));
}
Open in playground
Report an error