Skip to content

Commit fe7d9d8

Browse files
mu001999ojeda
authored andcommitted
rust: kernel: make impl_has_work compatible with more generics
Make the impl_has_work macro compatible with more complex generics such as lifetimes and const generic arguments. Signed-off-by: Roland Xu <[email protected]> Link: https://lore.kernel.org/r/ME0P282MB4890A180B99490CC65EF64FDCCEB2@ME0P282MB4890.AUSP282.PROD.OUTLOOK.COM Suggested-by: Benno Lossin <[email protected]> Link: #1077 [ Wrapped message to 72 columns. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 526c539 commit fe7d9d8

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

rust/kernel/workqueue.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,24 +482,26 @@ pub unsafe trait HasWork<T, const ID: u64 = 0> {
482482
/// use kernel::sync::Arc;
483483
/// use kernel::workqueue::{self, impl_has_work, Work};
484484
///
485-
/// struct MyStruct {
486-
/// work_field: Work<MyStruct, 17>,
485+
/// struct MyStruct<'a, T, const N: usize> {
486+
/// work_field: Work<MyStruct<'a, T, N>, 17>,
487+
/// f: fn(&'a [T; N]),
487488
/// }
488489
///
489490
/// impl_has_work! {
490-
/// impl HasWork<MyStruct, 17> for MyStruct { self.work_field }
491+
/// impl{'a, T, const N: usize} HasWork<MyStruct<'a, T, N>, 17>
492+
/// for MyStruct<'a, T, N> { self.work_field }
491493
/// }
492494
/// ```
493495
#[macro_export]
494496
macro_rules! impl_has_work {
495-
($(impl$(<$($implarg:ident),*>)?
497+
($(impl$({$($generics:tt)*})?
496498
HasWork<$work_type:ty $(, $id:tt)?>
497-
for $self:ident $(<$($selfarg:ident),*>)?
499+
for $self:ty
498500
{ self.$field:ident }
499501
)*) => {$(
500502
// SAFETY: The implementation of `raw_get_work` only compiles if the field has the right
501503
// type.
502-
unsafe impl$(<$($implarg),*>)? $crate::workqueue::HasWork<$work_type $(, $id)?> for $self $(<$($selfarg),*>)? {
504+
unsafe impl$(<$($generics)+>)? $crate::workqueue::HasWork<$work_type $(, $id)?> for $self {
503505
const OFFSET: usize = ::core::mem::offset_of!(Self, $field) as usize;
504506

505507
#[inline]
@@ -515,7 +517,7 @@ macro_rules! impl_has_work {
515517
pub use impl_has_work;
516518

517519
impl_has_work! {
518-
impl<T> HasWork<Self> for ClosureWork<T> { self.work }
520+
impl{T} HasWork<Self> for ClosureWork<T> { self.work }
519521
}
520522

521523
unsafe impl<T, const ID: u64> WorkItemPointer<ID> for Arc<T>

0 commit comments

Comments
 (0)