Skip to content

Commit

Permalink
refactor(ast): add comment not to use AstBuilder::copy (#3891)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
overlookmotel committed Jun 25, 2024
1 parent 5902331 commit 442aca3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/oxc_ast/src/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 442aca3

Please sign in to comment.