Why isn't `RefCell` unconditionally `Unpin`?

โš“ Rust    ๐Ÿ“… 2026-01-06    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 3      

surdeus

RefCell<T> is Unpin only when T is Unpin:

impl<T> Unpin for RefCell<T>
where
    T: Unpin + ?Sized,

(link)

Given that

  • RefCell<T> doesn't currently provide structural pinning of T, and
  • It can't provide structural pinning of T in the future because it has interior mutabilityโ€”a Pin<&RefCell<T>> allows you to obtain &RefCell<T>, which allows you to borrow &mut T and swap it. So there can't exist a way to get from Pin<&RefCell<T>> to Pin<&T>.

Why doesn't RefCell implement Unpin unconditionally?

4 posts - 3 participants

Read full topic

๐Ÿท๏ธ Rust_feed