refactor(ast): add comment not to use AstBuilder::copy (#3891)

As discussed in #3483, `AstBuilder::copy` is unsound. It's going to be a
hard slog removing all uses of it. This PR adds a comment to please not
introduce any further usages of it in meantime.
This commit is contained in:
overlookmotel 2024-06-25 02:12:43 +01:00 committed by GitHub
parent 5902331cac
commit 442aca3ba8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -68,11 +68,13 @@ impl<'a> AstBuilder<'a> {
Atom::from(String::from_str_in(value, self.allocator).into_bump_str())
}
/// # SAFETY
/// This method is completely unsound and should not be used.
/// We need to remove all uses of it. Please don't add any more!
/// <https://github.com/oxc-project/oxc/issues/3483>
#[inline]
pub fn copy<T>(self, src: &T) -> T {
// SAFETY:
// This should be safe as long as `src` is an reference from the allocator.
// But honestly, I'm not really sure if this is safe.
// SAFETY: Not safe (see above)
#[allow(unsafe_code)]
unsafe {
std::mem::transmute_copy(src)