Alexhuszagh / minimal-lexical

Minimal float parser primitives with a focus on compile times.
Other
21 stars 5 forks source link

[OTHER] Consider calling `ptr::drop_in_place` inside `StackVec::truncate_unchecked` #11

Open str4d opened 2 years ago

str4d commented 2 years ago

Description

https://github.com/Alexhuszagh/minimal-lexical/blob/e997c46656ebe83e696b866bd954da1fa3f64eef/src/stackvec.rs#L155-L163

This is technically sound as-is, because Limb is defined as an alias to either u32 or u64. But if in some future refactor Limb became a type with a real Drop impl, this code would become unsound.

Looping over the truncated elements and calling ptr::drop_in_place would future-proof this part of the code, while hopefully being optimised out by LLVM for the current Drop-less Limb types.

Additional Context

I'm in the process of migrating Fuchsia to use nom 7, which depends on minimal-lexical 0.1, and am opening issues in response to review comments (visible here: https://fuchsia-review.googlesource.com/c/fuchsia/+/589324).