[PATCH v3 02/13] rust: init: make `#[pin_data]` compatible with conditional compilation of fields

Benno Lossin posted 13 patches 2 years, 6 months ago
There is a newer version of this series
[PATCH v3 02/13] rust: init: make `#[pin_data]` compatible with conditional compilation of fields
Posted by Benno Lossin 2 years, 6 months ago
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.

Signed-off-by: Benno Lossin <benno.lossin@proton.me>
---
 rust/kernel/init/macros.rs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/rust/kernel/init/macros.rs b/rust/kernel/init/macros.rs
index fbaebd34f218..9182fdf99e7e 100644
--- a/rust/kernel/init/macros.rs
+++ b/rust/kernel/init/macros.rs
@@ -962,6 +962,7 @@ impl<$($impl_generics)*> $pin_data<$($ty_generics)*>
         where $($whr)*
         {
             $(
+                $(#[$($p_attr)*])*
                 $pvis unsafe fn $p_field<E>(
                     self,
                     slot: *mut $p_type,
@@ -971,6 +972,7 @@ impl<$($impl_generics)*> $pin_data<$($ty_generics)*>
                 }
             )*
             $(
+                $(#[$($attr)*])*
                 $fvis unsafe fn $field<E>(
                     self,
                     slot: *mut $type,
-- 
2.41.0
Re: [PATCH v3 02/13] rust: init: make `#[pin_data]` compatible with conditional compilation of fields
Posted by Martin Rodriguez Reboredo 2 years, 6 months ago
On 7/29/23 06:09, Benno Lossin wrote:
> 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.
> 
> Signed-off-by: Benno Lossin <benno.lossin@proton.me>
> ---
> [...]
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Re: [PATCH v3 02/13] rust: init: make `#[pin_data]` compatible with conditional compilation of fields
Posted by Gary Guo 2 years, 6 months ago
On Sat, 29 Jul 2023 09:09:23 +0000
Benno Lossin <benno.lossin@proton.me> wrote:

> 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.
> 
> Signed-off-by: Benno Lossin <benno.lossin@proton.me>

Reviewed-by: Gary Guo <gary@garyguo.net>

> ---
>  rust/kernel/init/macros.rs | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/rust/kernel/init/macros.rs b/rust/kernel/init/macros.rs
> index fbaebd34f218..9182fdf99e7e 100644
> --- a/rust/kernel/init/macros.rs
> +++ b/rust/kernel/init/macros.rs
> @@ -962,6 +962,7 @@ impl<$($impl_generics)*> $pin_data<$($ty_generics)*>
>          where $($whr)*
>          {
>              $(
> +                $(#[$($p_attr)*])*
>                  $pvis unsafe fn $p_field<E>(
>                      self,
>                      slot: *mut $p_type,
> @@ -971,6 +972,7 @@ impl<$($impl_generics)*> $pin_data<$($ty_generics)*>
>                  }
>              )*
>              $(
> +                $(#[$($attr)*])*
>                  $fvis unsafe fn $field<E>(
>                      self,
>                      slot: *mut $type,
Re: [PATCH v3 02/13] rust: init: make `#[pin_data]` compatible with conditional compilation of fields
Posted by Alice Ryhl 2 years, 6 months ago
Benno Lossin <benno.lossin@proton.me> writes:
> 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.
> 
> Signed-off-by: Benno Lossin <benno.lossin@proton.me>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>