@@ -44,7 +44,16 @@ impl<T: ?Sized> ArenaHeapItem<T> {
4444 & mut self . value as * mut T
4545 }
4646
47- pub ( crate ) fn value_mut ( & mut self ) -> & mut T {
47+ /// Returns a raw mutable pointer to the value
48+ ///
49+ /// This avoids creating a `&mut self` reference, which can lead to stacked borrows
50+ /// if shared references to the heap item exist
51+ pub ( crate ) fn as_value_ptr ( ptr : NonNull < Self > ) -> * mut T {
52+ // SAFETY: `&raw mut` computes the field address without creating a reference
53+ unsafe { & raw mut ( * ptr. as_ptr ( ) ) . value }
54+ }
55+
56+ fn value_mut ( & mut self ) -> & mut T {
4857 & mut self . value
4958 }
5059}
@@ -133,6 +142,15 @@ impl<'arena> ErasedArenaPointer<'arena> {
133142 self . 0 . as_ptr ( )
134143 }
135144
145+ /// Extend the lifetime of this erased arena pointer to 'static
146+ ///
147+ /// SAFETY:
148+ ///
149+ /// safe because the gc collector owns the arena and keeps it alive
150+ pub ( crate ) unsafe fn extend_lifetime ( self ) -> ErasedArenaPointer < ' static > {
151+ ErasedArenaPointer ( self . 0 , PhantomData )
152+ }
153+
136154 /// Returns an [`ArenaPointer`] for the current [`ErasedArenaPointer`]
137155 ///
138156 /// # Safety
@@ -178,6 +196,15 @@ impl<'arena, T> ArenaPointer<'arena, T> {
178196 pub fn to_erased ( self ) -> ErasedArenaPointer < ' arena > {
179197 self . 0
180198 }
199+
200+ /// Extend the lifetime of this arena pointer to 'static
201+ ///
202+ /// SAFETY:
203+ ///
204+ /// safe because the gc collector owns the arena and keeps it alive
205+ pub ( crate ) unsafe fn extend_lifetime ( self ) -> ArenaPointer < ' static , T > {
206+ ArenaPointer ( self . 0 . extend_lifetime ( ) , PhantomData )
207+ }
181208}
182209
183210const FULL_MASK : u8 = 0b0100_0000 ;
0 commit comments