The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Gary Guo <gary@garyguo.net>
To: Benno Lossin <benno.lossin@proton.me>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Martin Rodriguez Reboredo" <yakoyoku@gmail.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] rust: macros: allow generic parameter default values in `#[pin_data]`
Date: Sat, 23 Dec 2023 14:42:17 +0000	[thread overview]
Message-ID: <20231223144217.5c71727e.gary@garyguo.net> (raw)
In-Reply-To: <20231213220447.3613500-2-benno.lossin@proton.me>

On Wed, 13 Dec 2023 22:08:53 +0000
Benno Lossin <benno.lossin@proton.me> wrote:

> Add support for generic parameters defaults in `#[pin_data]` by using
> the newly introduced `decl_generics` instead of the `impl_generics`.
> 
> Before this would not compile:
> 
>     #[pin_data]
>     struct Foo<const N: usize = 0> {
>         // ...
>     }
> 
> because it would be expanded to this:
> 
>     struct Foo<const N: usize = 0> {
>         // ...
>     }
> 
>     const _: () = {
>         struct __ThePinData<const N: usize = 0> {
>             __phantom: ::core::marker::PhantomData<fn(Foo<N>) -> Foo<N>>,
>         }
>         impl<const N: usize = 0> ::core::clone::Clone for __ThePinData<N> {
>             fn clone(&self) -> Self {
>                 *self
>             }
>         }
> 
>         // [...] rest of expansion omitted
>     };
> 
> The problem is with the `impl<const N: usize = 0>`, since that is
> invalid Rust syntax. It should not mention the default value at all,
> since default values only make sense on type definitions.
> 
> The new `impl_generics` do not contain the default values, thus
> generating correct Rust code.
> 
> This is used by the next commit that puts `#[pin_data]` on
> `kernel::workqueue::Work`.
> 
> Signed-off-by: Benno Lossin <benno.lossin@proton.me>

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

> ---
> v1 -> v2:
> - clarify the change in the commit message
> - add motivation to the commit message
> 
>  rust/kernel/init/macros.rs | 19 ++++++++++++++++++-
>  rust/macros/pin_data.rs    |  3 ++-
>  2 files changed, 20 insertions(+), 2 deletions(-)

  parent reply	other threads:[~2023-12-23 14:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-13 22:08 [PATCH v2 1/3] rust: macros: add `decl_generics` to `parse_generics()` Benno Lossin
2023-12-13 22:08 ` [PATCH v2 2/3] rust: macros: allow generic parameter default values in `#[pin_data]` Benno Lossin
2023-12-14  3:11   ` Martin Rodriguez Reboredo
2023-12-23 14:42   ` Gary Guo [this message]
2024-01-04 15:18   ` Alice Ryhl
2023-12-13 22:09 ` [PATCH v2 3/3] rust: workqueue: add `#[pin_data]` to `Work` Benno Lossin
2023-12-14  3:13   ` Martin Rodriguez Reboredo
2023-12-18 17:47     ` Benno Lossin
2023-12-18 20:49       ` Martin Rodriguez Reboredo
2023-12-23 14:43   ` Gary Guo
2024-01-04 15:19   ` Alice Ryhl
2023-12-14  2:57 ` [PATCH v2 1/3] rust: macros: add `decl_generics` to `parse_generics()` Martin Rodriguez Reboredo
2023-12-23 14:41 ` Gary Guo
2024-01-04 15:17 ` Alice Ryhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231223144217.5c71727e.gary@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    --cc=yakoyoku@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox