Re: [PATCH 0/3] rust: macros: vtable: add `#[optional]` attribute

From: Miguel Ojeda

Date: Fri Oct 02 2026 - 15:10:44 EST


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.

By the way, did you consider allowing `unused_variables`? It could be
nice to not have to use `_` in the signatures.

Cheers,
Miguel