fitzgen / bumpalo

A fast bump allocation arena for Rust
https://docs.rs/bumpalo
Apache License 2.0
1.35k stars 110 forks source link

Impossible to move the stored value out of the `bumpalo::Boxed::Box`. #161

Closed zetanumbers closed 1 year ago

zetanumbers commented 2 years ago

Basically, std::boxed::Box allows us to move the stored value out of it just by dereferencing it:

fn foo(b: Box<AtomicI32>) -> AtomicI32 {
  *b
}

But equivalent code does not work for bumpalo's box:

fn foo(b: bumpalo::boxed::Box<'_, AtomicI32>) -> AtomicI32 {
  *b
}

Fails with

cannot move out of dereference of `bumpalo::boxed::Box<'_, AtomicI32>`
move occurs because value has type `AtomicI32`, which does not implement the `Copy` trait`

There's currently unstable associated function std::boxed::Box::into_inner, that allows us to do the same thing. It follows naming and some other conventions, and can be implemented easily. I propose to implement that.

fn foo(b: bumpalo::boxed::Box<'_, AtomicI32>) -> AtomicI32 {
  bumpalo::boxed::Box::into_inner(b)
}
zetanumbers commented 1 year ago

Perhaps, dropck_eyepatch could be added via feature, or after its stabilization.