rust: macros: drop underscores from `#[optional]` methods
Subsystems (2)
Gary Guo
reviewerPATCH 1/1 rust: macros: drop underscores from `#[optional]` methods
In the vtable macro, #[optional] methods do not have a body, so they should not require underscore-prefixing the function parameters just like mandatory trait methods. Add #[allow(unused_variables)] to make underscore unnecessary and drop the prefix from existing users.
Suggested-by Miguel Ojeda <[email protected]>
Link https://lore.kernel.org/rust-for-linux/CANiq72neqitKHftQ9UVJaKLkcUdX8uAWLtoE08-G784mqX+H9w@mail.gmail.com/ open here
Signed-off-by Gary Guo <[email protected]>
--- rust/kernel/miscdevice.rs | 24 ++++++++++-------------- rust/macros/vtable.rs | 2 ++ 2 files changed, 12 insertions(+), 14 deletions(-)
rust/kernel/miscdevice.rs +10 -14
@@ -179,18 +179,18 @@ fn release(device: Self::File, _file: &File) {/// `vma`. #[optional] fn mmap ( - _device: <Self ::File as ForeignOwnable >::Borrowed <'_>, - _file: &File , - _vma: &VmaNew , + device: <Self ::File as ForeignOwnable >::Borrowed <'_>, + file: &File , + vma: &VmaNew , ) ->Result ;/// Read from this miscdevice. #[optional] -fn read_iter (_kiocb:Kiocb <'_,Self ::File >, _iov: &mut IovIterDest <'_>) ->Result <usize >; +fn read_iter (kiocb:Kiocb <'_,Self ::File >, iov: &mut IovIterDest <'_>) ->Result <usize >;/// Write to this miscdevice. #[optional] -fn write_iter (_kiocb:Kiocb <'_,Self ::File >, _iov: &mut IovIterSource <'_>) ->Result <usize >; +fn write_iter (kiocb:Kiocb <'_,Self ::File >, iov: &mut IovIterSource <'_>) ->Result <usize >;/// Handler for ioctls. ///
@@ -199,10 +199,10 @@ fn mmap(/// [`kernel::ioctl`]: mod@crate::ioctl #[optional] fn ioctl ( - _device: <Self ::File as ForeignOwnable >::Borrowed <'_>, - _file: &File , - _cmd:u32 , - _arg:usize , + device: <Self ::File as ForeignOwnable >::Borrowed <'_>, + file: &File , + cmd:u32 , + arg:usize , ) ->Result <isize >;/// Handler for ioctls.
@@ -223,11 +223,7 @@ fn compat_ioctl(/// Show info for this fd. #[optional] -fn show_fdinfo ( - _device: <Self ::File as ForeignOwnable >::Borrowed <'_>, - _m: &SeqFile , - _file: &File , - ); +fn show_fdinfo (device: <Self ::File as ForeignOwnable >::Borrowed <'_>, m: &SeqFile , file: &File ); }/// A vtable for the file operations of a Rust miscdevice.
rust/macros/vtable.rs +2 -0
@@ -79,6 +79,8 @@ fn handle_trait(mut item: ItemTrait) -> Result<ItemTrait> { }));// Ensure that the function is never code generated unless used. fn_item.attrs.push (parse_quote! (#[inline] )); +// Injected default implementation does not use function parameters. + fn_item.attrs.push (parse_quote! (#[allow(unused_variables)] )); }// We don't know on the implementation-site whether a method is required or provided
---
base-commit: 7cfbf79c66c63e807ea452abf0546e6f6d6833a6
change-id: 20261126-dev-optional-50abc27e06cc
Best regards,
Signature · 1 line
Gary Guo <[email protected]>
Quoted 9 lines · Gary Guo
In the
vtablemacro,#[optional]methods do not have a body, so they should not require underscore-prefixing the function parameters just like mandatory trait methods. Add#[allow(unused_variables)]to make underscore unnecessary and drop the prefix from existing users.
Reviewed-by Alice Ryhl <[email protected]>