fitzgen / bumpalo

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

`Vec::set_len` example is UB #166

Closed zetanumbers closed 1 year ago

zetanumbers commented 2 years ago

While i hope it's not, it seems intentional. If it is... why? https://github.com/fitzgen/bumpalo/blob/fa52577688284d73b44cc8f49671ef02ebdea14b/src/collections/vec.rs#L1028-L1042

zetanumbers commented 2 years ago

Basically deref_mut happens inside of the Vec::drop, so the &mut [char] is created to uninitialized memory.

fitzgen commented 2 years ago

I think this was taken from std but it looks like std's example is different now (if it was actually taken from there).

Happy to receive a PR to fix this, as docs/examples definitely shouldn't be this eggregiously wrong.