Skip to content

Commit 82c082c

Browse files
committed
fix: use self_alloc provenance for parent pointers in cursor
1 parent 72c3be4 commit 82c082c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/cursor.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,19 @@ impl NodeData {
256256
green: Green,
257257
mutable: bool,
258258
) -> ptr::NonNull<NodeData> {
259+
// Extract parent's self_alloc before wrapping in ManuallyDrop.
260+
// We read it while we still OWN the SyntaxNode (before any shared refs).
261+
let parent_alloc = parent.as_ref().map(|p| {
262+
// p is &SyntaxNode from owned Option — safe to read here.
263+
// UnsafeCell::get gives *mut without freezing.
264+
let node_data = unsafe { *p.ptr.get() };
265+
unsafe { ptr::NonNull::new_unchecked((*node_data.as_ptr()).self_alloc) }
266+
});
259267
let parent = ManuallyDrop::new(parent);
260268
let res = NodeData {
261269
_c: Count::new(),
262270
rc: Cell::new(1),
263-
parent: Cell::new(parent.as_ref().map(|it| it.ptr())),
271+
parent: Cell::new(parent_alloc),
264272
index: Cell::new(index),
265273
green,
266274

0 commit comments

Comments
 (0)