Re: [PATCH 0/3] rust: macros: vtable: add `#[optional]` attribute
From: Gary Guo
Date: Fri Oct 02 2026 - 16:39:44 EST
On Fri Oct 2, 2026 at 8:10 PM BST, Miguel Ojeda wrote:
> On Tue, Aug 11, 2026 at 3:56 PM Gary Guo <gary@xxxxxxxxxxx> wrote:
>>
>> Currently there are a lot of boilerplate with the
>> `build_error!(VTABLE_DEFAULT_ERROR)` because Rust want a default
>> implementation but we insert `NULL` into C vtable and never call the
>> Rust-side method if it is not overridden.
>>
>> Add an `#[optional]` attribute that injects the same default
>> implementation to avoid duplicating this everywhere. As an example, the
>> misc device vtable trait is converted.
>>
>> Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
>
> Applied to `rust-next` -- thanks everyone!
>
> [ Reworded for typo. - Miguel ]
>
> [ Rewrapped docs. Reworded message, comment and error for typos. Rebased.
> - Miguel ]
>
> [ Reworded title for prefix. - Miguel ]
>
> I was tempted to replace the hardcoded message with the
> `VTABLE_DEFAULT_ERROR` constant, but I assume you did it so that we
> can just remove the constant later when everyone is migrated.
Correct.
>
> By the way, did you consider allowing `unused_variables`? It could be
> nice to not have to use `_` in the signatures.
I didn't because existing users are all _ prefixed already. But it does make
sense to add that to avoid having to prefix them, just like mandatory methods.
Best,
Gary