Skip to content

Commit a0527c8

Browse files
bonziniBennoLossin
authored andcommitted
examples, tests: prepare to enable other lints related to safety comments
Signed-off-by: Paolo Bonzini <[email protected]>
1 parent c4efe2a commit a0527c8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

examples/linked_list.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ impl PinnedDrop for ListHead {
9292
struct Link(Cell<NonNull<ListHead>>);
9393

9494
impl Link {
95+
/// # Safety
96+
///
97+
/// The contents of the pointer should form a consistent circular
98+
/// linked list; for example, a "next" link should be pointed back
99+
/// by the target `ListHead`'s "prev" link and a "prev" link should be
100+
/// pointed back by the target `ListHead`'s "next" link.
95101
#[inline]
96102
unsafe fn new_unchecked(ptr: NonNull<ListHead>) -> Self {
97103
Self(Cell::new(ptr))

tests/ring_buf.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<T, const SIZE: usize> RingBuffer<T, SIZE> {
6565
// SAFETY: We do not move `this`.
6666
let this = unsafe { self.get_unchecked_mut() };
6767
let next_head = unsafe { this.advance(this.head) };
68-
// SAFETY: `head` and `tail` point into the same buffer.
68+
// `head` and `tail` point into the same buffer.
6969
if ptr::eq(next_head, this.tail) {
7070
// We cannot advance `head`, since `next_head` would point to the same slot as `tail`,
7171
// which is currently live.
@@ -105,6 +105,9 @@ impl<T, const SIZE: usize> RingBuffer<T, SIZE> {
105105
Some(unsafe { init_from_closure(remove_init) })
106106
}
107107

108+
/// # Safety
109+
///
110+
/// TODO
108111
unsafe fn advance(&mut self, ptr: *mut T) -> *mut T {
109112
let ptr = ptr.add(1);
110113
let origin: *mut _ = addr_of_mut!(self.buffer);

0 commit comments

Comments
 (0)