diff --git a/src/table/memo.rs b/src/table/memo.rs index 65675df..d0c868e 100644 --- a/src/table/memo.rs +++ b/src/table/memo.rs @@ -43,7 +43,7 @@ struct MemoEntryData { type_id: TypeId, /// A pointer to `std::mem::drop::>` for the erased memo type `M` - drop_fn: fn(Arc), + to_dyn_any_fn: fn(Arc) -> Arc, /// An [`ArcSwap`][] to a `Arc` for the erased memo type `M` arc_swap: ArcSwap, @@ -61,9 +61,11 @@ impl MemoTable { unsafe { std::mem::transmute::, Arc>(memo) } } - fn drop_fn() -> fn(Arc) { - let f: fn(Arc) = std::mem::drop::>; - unsafe { std::mem::transmute::), fn(Arc)>(f) } + fn to_dyn_any_fn() -> fn(Arc) -> Arc { + let f: fn(Arc) -> Arc = |x| x; + unsafe { + std::mem::transmute::) -> Arc, fn(Arc) -> Arc>(f) + } } pub(crate) fn insert( @@ -77,7 +79,7 @@ impl MemoTable { data: Some(MemoEntryData { type_id, - drop_fn: _, + to_dyn_any_fn: _, arc_swap, }), }) = self.memos.read().get(memo_ingredient_index.as_usize()) @@ -106,7 +108,7 @@ impl MemoTable { memos[memo_ingredient_index] = MemoEntry { data: Some(MemoEntryData { type_id: TypeId::of::(), - drop_fn: Self::drop_fn::(), + to_dyn_any_fn: Self::to_dyn_any_fn::(), arc_swap: ArcSwap::new(Self::to_dummy(memo)), }), }; @@ -122,7 +124,7 @@ impl MemoTable { data: Some(MemoEntryData { type_id, - drop_fn: _, + to_dyn_any_fn: _, arc_swap, }), }) = memos.get(memo_ingredient_index.as_usize()) @@ -145,12 +147,12 @@ impl Drop for MemoEntry { fn drop(&mut self) { if let Some(MemoEntryData { type_id: _, - drop_fn, + to_dyn_any_fn, arc_swap, }) = self.data.take() { let arc = arc_swap.into_inner(); - drop_fn(arc); + std::mem::drop(to_dyn_any_fn(arc)); } } }