Skip to content

Commit e71d7e3

Browse files
tamirdojeda
authored andcommitted
rust: list: simplify macro capture
Avoid manually capturing generics; use `ty` to capture the whole type instead. Reviewed-by: Christian Schrefl <chrisi.schrefl@gmail.com> Tested-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Tamir Duberstein <tamird@gmail.com> Link: https://lore.kernel.org/r/20250709-list-no-offset-v4-1-a429e75840a9@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent b0c7d8c commit e71d7e3

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

rust/kernel/list/impl_list_item_mod.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,15 @@ pub unsafe trait HasListLinks<const ID: u64 = 0> {
4343
macro_rules! impl_has_list_links {
4444
($(impl$(<$($implarg:ident),*>)?
4545
HasListLinks$(<$id:tt>)?
46-
for $self:ident $(<$($selfarg:ty),*>)?
46+
for $self:ty
4747
{ self$(.$field:ident)* }
4848
)*) => {$(
4949
// SAFETY: The implementation of `raw_get_list_links` only compiles if the field has the
5050
// right type.
5151
//
5252
// The behavior of `raw_get_list_links` is not changed since the `addr_of_mut!` macro is
5353
// equivalent to the pointer offset operation in the trait definition.
54-
unsafe impl$(<$($implarg),*>)? $crate::list::HasListLinks$(<$id>)? for
55-
$self $(<$($selfarg),*>)?
56-
{
54+
unsafe impl$(<$($implarg),*>)? $crate::list::HasListLinks$(<$id>)? for $self {
5755
const OFFSET: usize = ::core::mem::offset_of!(Self, $($field).*) as usize;
5856

5957
#[inline]
@@ -85,18 +83,14 @@ where
8583
macro_rules! impl_has_list_links_self_ptr {
8684
($(impl$({$($implarg:tt)*})?
8785
HasSelfPtr<$item_type:ty $(, $id:tt)?>
88-
for $self:ident $(<$($selfarg:ty),*>)?
86+
for $self:ty
8987
{ self.$field:ident }
9088
)*) => {$(
9189
// SAFETY: The implementation of `raw_get_list_links` only compiles if the field has the
9290
// right type.
93-
unsafe impl$(<$($implarg)*>)? $crate::list::HasSelfPtr<$item_type $(, $id)?> for
94-
$self $(<$($selfarg),*>)?
95-
{}
91+
unsafe impl$(<$($implarg)*>)? $crate::list::HasSelfPtr<$item_type $(, $id)?> for $self {}
9692

97-
unsafe impl$(<$($implarg)*>)? $crate::list::HasListLinks$(<$id>)? for
98-
$self $(<$($selfarg),*>)?
99-
{
93+
unsafe impl$(<$($implarg)*>)? $crate::list::HasListLinks$(<$id>)? for $self {
10094
const OFFSET: usize = ::core::mem::offset_of!(Self, $field) as usize;
10195

10296
#[inline]

0 commit comments

Comments
 (0)