mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
Make dropping an empty BTreeMap free
rust-lang/rust#161375 ([code example](https://godbolt.org/z/v594PEsr7)) shows that drop of an empty BTree map walks the dying_next path and so is not free. I tracked this down to 7b28036c63 in 1.56.0 using godbolt’s version comparison.
When the Btree map has no root we use the ManuallyDrop to safely drop the allocator early resulting in a free drop and a `ret` instead of the `dying_next` path.
Includes codegen test which correctly catches the prior dying_next case, which I based on `uninit-aggregate-field.rs`.
Fixes rust-lang/rust#161375