Skip to content

Commit 24c14ab

Browse files
committed
Fix miri warning
1 parent d67604f commit 24c14ab

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,15 @@ impl<T> RingBuffer<T> {
115115
// an initialized slot when reading, or to a slot that may be written
116116
// when writing. This helper performs unchecked indexing into the
117117
// backing slice using the internal mask.
118-
unsafe { (&mut (*self.ptr)).get_unchecked_mut(idx & self.mask) }
118+
//
119+
// We use raw pointer arithmetic here to avoid creating a `&mut` reference
120+
// to the entire backing array, which would cause aliasing issues in Miri
121+
// when both producer and consumer threads call this method concurrently.
122+
// Instead, we create a reference only to the specific element we need.
123+
unsafe {
124+
let base = self.ptr as *mut MaybeUninit<T>;
125+
&mut *base.add(idx & self.mask)
126+
}
119127
}
120128
}
121129

0 commit comments

Comments
 (0)