@@ -44,7 +44,17 @@ 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
53+ // reference
54+ unsafe { & raw mut ( * ptr. as_ptr ( ) ) . value }
55+ }
56+
57+ fn value_mut ( & mut self ) -> & mut T {
4858 & mut self . value
4959 }
5060}
@@ -133,6 +143,15 @@ impl<'arena> ErasedArenaPointer<'arena> {
133143 self . 0 . as_ptr ( )
134144 }
135145
146+ /// Extend the lifetime of this erased arena pointer to 'static
147+ ///
148+ /// SAFETY:
149+ ///
150+ /// safe because the gc collector owns the arena and keeps it alive
151+ pub ( crate ) unsafe fn extend_lifetime ( self ) -> ErasedArenaPointer < ' static > {
152+ ErasedArenaPointer ( self . 0 , PhantomData )
153+ }
154+
136155 /// Returns an [`ArenaPointer`] for the current [`ErasedArenaPointer`]
137156 ///
138157 /// # Safety
@@ -178,6 +197,15 @@ impl<'arena, T> ArenaPointer<'arena, T> {
178197 pub fn to_erased ( self ) -> ErasedArenaPointer < ' arena > {
179198 self . 0
180199 }
200+
201+ /// extend the lifetime of this arena pointer to 'static
202+ ///
203+ /// SAFETY:
204+ ///
205+ /// safe because the gc collector owns the arena and keeps it alive
206+ pub ( crate ) unsafe fn extend_lifetime ( self ) -> ArenaPointer < ' static , T > {
207+ ArenaPointer ( unsafe { self . 0 . extend_lifetime ( ) } , PhantomData )
208+ }
181209}
182210
183211const FULL_MASK : u8 = 0b0100_0000 ;
0 commit comments