Skip to content

Commit 48569f7

Browse files
Oliver Mangoldintel-lab-lkp
authored andcommitted
rust: Add missing SAFETY documentation for ARef example
SAFETY comment in rustdoc example was just 'TODO'. Fixed. Signed-off-by: Oliver Mangold <oliver.mangold@pm.me>
1 parent 7852f48 commit 48569f7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

rust/kernel/types.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,17 @@ impl<T: RefCounted> ARef<T> {
498498
///
499499
/// struct Empty {}
500500
///
501-
/// # // SAFETY: TODO.
501+
/// // SAFETY: The `RefCounted` implementation for `Empty` does not count references
502+
/// // and never frees the underlying object. Thus we can act as having a
503+
/// // refcount on the object that we pass to the newly created `ARef`.
502504
/// unsafe impl RefCounted for Empty {
503505
/// fn inc_ref(&self) {}
504506
/// unsafe fn dec_ref(_obj: NonNull<Self>) {}
505507
/// }
506508
///
507509
/// let mut data = Empty {};
508510
/// let ptr = NonNull::<Empty>::new(&mut data).unwrap();
509-
/// # // SAFETY: TODO.
511+
/// // SAFETY: We keep `data` around longer than the `ARef`.
510512
/// let data_ref: ARef<Empty> = unsafe { ARef::from_raw(ptr) };
511513
/// let raw_ptr: NonNull<Empty> = ARef::into_raw(data_ref);
512514
///

0 commit comments

Comments
 (0)