Commit f8badd15 authored by Benno Lossin's avatar Benno Lossin Committed by Miguel Ojeda

rust: init: make `#[pin_data]` compatible with conditional compilation of fields

This patch allows one to write
```
#[pin_data]
pub struct Foo {
    #[cfg(CONFIG_BAR)]
    a: Bar,
    #[cfg(not(CONFIG_BAR))]
    a: Baz,
}
```
Before, this would result in a compile error, because `#[pin_data]`
would generate two functions named `a` for both fields unconditionally.
Reviewed-by: default avatarMartin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: default avatarGary Guo <gary@garyguo.net>
Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
Signed-off-by: default avatarBenno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20230814084602.25699-3-benno.lossin@proton.meSigned-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent b3068ac3
...@@ -962,6 +962,7 @@ impl<$($impl_generics)*> $pin_data<$($ty_generics)*> ...@@ -962,6 +962,7 @@ impl<$($impl_generics)*> $pin_data<$($ty_generics)*>
where $($whr)* where $($whr)*
{ {
$( $(
$(#[$($p_attr)*])*
$pvis unsafe fn $p_field<E>( $pvis unsafe fn $p_field<E>(
self, self,
slot: *mut $p_type, slot: *mut $p_type,
...@@ -971,6 +972,7 @@ impl<$($impl_generics)*> $pin_data<$($ty_generics)*> ...@@ -971,6 +972,7 @@ impl<$($impl_generics)*> $pin_data<$($ty_generics)*>
} }
)* )*
$( $(
$(#[$($attr)*])*
$fvis unsafe fn $field<E>( $fvis unsafe fn $field<E>(
self, self,
slot: *mut $type, slot: *mut $type,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment