Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
str4d opened this issue Dec 19, 2021 · 0 comments
Assignees

Comments

@str4d
Copy link
Contributor

str4d commented Dec 19, 2021

Description

/// Truncate vector to new length, dropping any items after `len`.
///
/// # Safety
///
/// Safe as long as `len <= self.capacity()`.
unsafe fn truncate_unchecked(&mut self, len: usize) {
debug_assert!(len <= self.capacity());
self.length = len as u16;
}

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants