Skip to content

Commit 0a2f765

Browse files
committed
Remove DerefMut impl for RootedGuard
Signed-off-by: Greg Morenz <[email protected]>
1 parent d7a7b16 commit 0a2f765

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

mozjs/src/gc/root.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ impl<'a, T: 'a + RootKind> RootedGuard<'a, T> {
5050
// SAFETY: self.root points to an inbounds allocation
5151
unsafe { (&raw mut (*self.root).ptr).cast() }
5252
}
53+
54+
/// Safety: GC must not run during the lifetime of the returned reference.
55+
pub unsafe fn as_mut<'b: 'a>(&mut self) -> &'b mut T {
56+
&mut *(self.as_ptr())
5357
}
5458

5559
pub fn get(&self) -> T
@@ -70,6 +74,16 @@ impl<'a, T: 'a + RootKind> RootedGuard<'a, T> {
7074
}
7175
}
7276

77+
impl<'a, T> RootedGuard<'a, Option<T>>
78+
where
79+
Option<T>: RootKind,
80+
{
81+
pub fn take(&mut self) -> Option<T> {
82+
// Safety: No GC occurs during take call
83+
unsafe { self.as_mut().take() }
84+
}
85+
}
86+
7387
impl<'a, T: 'a + RootKind> Deref for RootedGuard<'a, T> {
7488
type Target = T;
7589
fn deref(&self) -> &T {
@@ -78,13 +92,6 @@ impl<'a, T: 'a + RootKind> Deref for RootedGuard<'a, T> {
7892
}
7993
}
8094

81-
impl<'a, T: 'a + RootKind> DerefMut for RootedGuard<'a, T> {
82-
fn deref_mut(&mut self) -> &mut T {
83-
// SAFETY: The rooted value is initialized as long as we exist
84-
unsafe { (*self.root).ptr.assume_init_mut() }
85-
}
86-
}
87-
8895
impl<'a, T: 'a + RootKind> Drop for RootedGuard<'a, T> {
8996
fn drop(&mut self) {
9097
// SAFETY: The rooted value is initialized as long as we exist

0 commit comments

Comments
 (0)