Fix RefCell borrow panic with unboxed closures

Closes #18711