[PATCH 3/3] rust: list: add warning to List::remove docs about mem::take

Alice Ryhl posted 3 patches 2 months, 4 weeks ago
[PATCH 3/3] rust: list: add warning to List::remove docs about mem::take
Posted by Alice Ryhl 2 months, 4 weeks ago
The previous patches in this series illustrate why the List::remove
method is really dangerous. I think the real takeaway here is to replace
the linked lists with a different data structure without this unsafe
footgun, but for now we fix the bugs and add a warning to the docs.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
 rust/kernel/list.rs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs
index 7355bbac16a7fe7feeb8bc6408671817b186b21d..8349ff32fc37ff7141fb7c62d26653bda6507f91 100644
--- a/rust/kernel/list.rs
+++ b/rust/kernel/list.rs
@@ -576,6 +576,9 @@ pub fn pop_front(&mut self) -> Option<ListArc<T, ID>> {
     /// This returns `None` if the item is not in the list. (Note that by the safety requirements,
     /// this means that the item is not in any list.)
     ///
+    /// When using this method, be careful with using `mem::take` on the same list as that may
+    /// result in violating the safety requirements of this method.
+    ///
     /// # Safety
     ///
     /// `item` must not be in a different linked list (with the same id).

-- 
2.51.2.1041.gc1ab5b90ca-goog
Re: [PATCH 3/3] rust: list: add warning to List::remove docs about mem::take
Posted by Miguel Ojeda 2 months, 4 weeks ago
On Tue, Nov 11, 2025 at 3:23 PM Alice Ryhl <aliceryhl@google.com> wrote:
>
> +    /// When using this method, be careful with using `mem::take` on the same list as that may
> +    /// result in violating the safety requirements of this method.

I suggested adding an example or similar to hopefully help prevent
this in the future, and this note is "to the point", so that is great.
Thanks for adding it!

Nit: intra-doc link [`core::mem::take`]

Cheers,
Miguel