On 2/24/2026 2:28 AM, Alice Ryhl wrote:
> On Mon, Feb 23, 2026 at 2:13 AM Joel Fernandes <[email protected]> wrote:
>>
>> Hi Eliot,
>>
>> On 2/20/2026 3:16 AM, Eliot Courtney wrote:
>>> On Thu Feb 19, 2026 at 5:55 AM JST, Joel Fernandes wrote:
>>>> +/// Create a C doubly-circular linked list interface `CList` from a raw 
>>>> `list_head` pointer.
>>>> +///
>>>> +/// This macro creates a `CList<T, OFFSET>` that can iterate over items 
>>>> of type `$rust_type`
>>>> +/// linked via the `$field` field in the underlying C struct `$c_type`.
>>>> +///
>>>> +/// # Arguments
>>>> +///
>>>> +/// - `$head`: Raw pointer to the sentinel `list_head` object (`*mut 
>>>> bindings::list_head`).
>>>> +/// - `$rust_type`: Each item's rust wrapper type.
>>>> +/// - `$c_type`: Each item's C struct type that contains the embedded 
>>>> `list_head`.
>>>> +/// - `$field`: The name of the `list_head` field within the C struct.
>>>> +///
>>>> +/// # Safety
>>>> +///
>>>> +/// This is an unsafe macro. The caller must ensure:
>>>> +///
>>>> +/// - `$head` is a valid, initialized sentinel `list_head` pointing to a 
>>>> list that remains
>>>> +///   unmodified for the lifetime of the rust `CList`.
>>>> +/// - The list contains items of type `$c_type` linked via an embedded 
>>>> `$field`.
>>>> +/// - `$rust_type` is `#[repr(transparent)]` over `$c_type` or has 
>>>> compatible layout.
>>>> +///
>>>> +/// # Examples
>>>> +///
>>>> +/// Refer to the examples in this module's documentation.
>>>> +#[macro_export]
>>>> +macro_rules! clist_create {
>>>> +    ($head:expr, $rust_type:ty, $c_type:ty, $($field:tt).+) => {{
>>>> +        // Compile-time check that field path is a list_head.
>>>> +        let _: fn(*const $c_type) -> *const $crate::bindings::list_head =
>>>> +            |p| &raw const (*p).$($field).+;
>>>> +
>>>> +        // Calculate offset and create `CList`.
>>>> +        const OFFSET: usize = ::core::mem::offset_of!($c_type, 
>>>> $($field).+);
>>>> +        $crate::ffi::clist::CList::<$rust_type, OFFSET>::from_raw($head)
>>>> +    }};
>>>> +}
>>>
>>> This uses offset_of! in a way that requires the offset_of_nested
>>> feature, so it doesn't build in rust 1.78.0. The feature is already
>>> added to rust_allowed_features, so I think it's ok to add
>>> #![feature(offset_of_nested)].
>>
>> Maybe I am missing something, but why should the feature be gated behind
>> that if all compiler versions (>= 1.78) support it either in a stable way
>> or via an unstable feature flag?
> 
> The rust_allowed_features list only applies to drivers and such. It
> doesn't apply to the Rust crates in the rust/ directory, which need to
> use #![feature] annotations manually.

Ah fun! Ok, I will add it in in. :)

thanks,

--
Joel Fernandes

Reply via email to