diff --git a/Cargo.toml b/Cargo.toml index 212956f..0b2ee6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ fxhash = "0.2.1" parking_lot = "0.11.2" # Arc -triomphe = "0.1.3" +triomphe = "0.1.7" sptr = "0.3.2" [dependencies.serde] diff --git a/src/syntax/node.rs b/src/syntax/node.rs index 8969e5e..5452d3e 100644 --- a/src/syntax/node.rs +++ b/src/syntax/node.rs @@ -170,15 +170,6 @@ impl SyntaxNode { unsafe { &*self.data } } - /// # Safety: - /// Caller must ensure that the access to the underlying data is unique (no active _mutable or immutable_ - /// references). - #[inline] - #[allow(clippy::mut_from_ref)] - unsafe fn data_mut(&self) -> &mut NodeData { - &mut *self.data - } - #[inline] pub(super) fn clone_uncounted(&self) -> Self { Self { data: self.data } @@ -346,8 +337,11 @@ impl SyntaxNode { Kind::Root(green, _resolver) => green.into(), _ => unreachable!(), }; - // safety: we have just created `ret` and have not shared it - unsafe { ret.data_mut() }.green = green; + // safety: we have just created `ret` and have not shared it. + // Also, we use `addr_of_mut` here in order to not have to go through a `&mut *ret.data`, + // which would invalidate the reading provenance of `green`, since `green` is contained in + // the date once we have written it here. + unsafe { ptr::addr_of_mut!((*ret.data).green).write(green) }; ret }