From 442aca3ba8bdcc1cdd0f2cd00d5783a5901f3a79 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Tue, 25 Jun 2024 02:12:43 +0100 Subject: [PATCH] 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. --- crates/oxc_ast/src/ast_builder.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/oxc_ast/src/ast_builder.rs b/crates/oxc_ast/src/ast_builder.rs index 8c8edb2ec..b5466b10d 100644 --- a/crates/oxc_ast/src/ast_builder.rs +++ b/crates/oxc_ast/src/ast_builder.rs @@ -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! + /// #[inline] pub fn copy(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)