diff --git a/crates/swc_visit/src/util/map.rs b/crates/swc_visit/src/util/map.rs index 1b3eb7d07b8c..992d2332645f 100644 --- a/crates/swc_visit/src/util/map.rs +++ b/crates/swc_visit/src/util/map.rs @@ -1,4 +1,4 @@ -use std::{mem, ptr}; +use std::ptr; /// Copied from `syntax::ptr::P` of rustc. pub trait Map { @@ -13,17 +13,15 @@ pub trait Map { } impl Map for Box { - fn map(mut self, f: F) -> Self + fn map(self, f: F) -> Self where F: FnOnce(T) -> T, { - let p: *mut T = &mut *self; - // Leak self in case of panic. // FIXME(eddyb) Use some sort of "free guard" that // only deallocates, without dropping the pointee, // in case the call the `f` below ends in a panic. - mem::forget(self); + let p = Box::into_raw(self); unsafe { ptr::write(p, f(ptr::read(p)));