Re: [PATCH] rust: lib: Add necessary unsafes for container_of
From: Miguel Ojeda
Date: Mon Nov 17 2025 - 04:00:23 EST
On Mon, Nov 17, 2025 at 9:24 AM Philipp Stanner <phasta@xxxxxxxxxxx> wrote:
>
> OK, so container_of is an unsafe function and all uses of it must be
> guarded by an unsafe block.
>
> If I do this, however
>
> @@ -217,7 +217,7 @@ unsafe fn view_value(me: *mut $crate::list::ListLinks<$num>) -> *const Self {
> @@ -242,7 +242,7 @@ unsafe fn post_remove(me: *mut $crate::list::ListLinks<$num>) -> *const Self {
>
> then the compiler gets sad again, complaining precisely about the
> internals of container_of:
>
> 269 | unsafe fn prepare_to_insert(me: *const Self) -> *mut $crate::list::ListLinks<$num> {
> 321 | unsafe fn view_value(links_field: *mut $crate::list::ListLinks<$num>) -> *const Self {
Given the signatures above, it seems to me you have done it for 2 out
of 4 of the calls, thus the compiler complains as expected.
Cheers,
Miguel