From: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
To: "Benno Lossin" <benno.lossin@proton.me>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Sumera Priyadarsini" <sylphrenadin@gmail.com>,
"Vincenzo Palazzo" <vincenzopalazzodev@gmail.com>,
"Asahi Lina" <lina@asahilina.net>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/3] rust: macros: add `decl_generics` to `parse_generics()`
Date: Wed, 13 Dec 2023 23:57:29 -0300 [thread overview]
Message-ID: <f9b8f95e-1e72-4907-9964-6a4ecfc435b1@gmail.com> (raw)
In-Reply-To: <20231213220447.3613500-1-benno.lossin@proton.me>
On 12/13/23 19:08, Benno Lossin wrote:
> The generic parameters on a type definition can specify default values.
> Currently `parse_generics()` cannot handle this though. For example when
> parsing the following generics:
>
> <T: Clone, const N: usize = 0>
>
> The `impl_generics` will be set to `T: Clone, const N: usize = 0` and
> `ty_generics` will be set to `T, N`. Now using the `impl_generics` on an
> impl block:
>
> impl<$($impl_generics)*> Foo {}
>
> will result in invalid Rust code, because default values are only
> available on type definitions.
>
> Therefore add parsing support for generic parameter default values using
> a new kind of generics called `decl_generics` and change the old
> behavior of `impl_generics` to not contain the generic parameter default
> values.
>
> Now `Generics` has three fields:
> - `impl_generics`: the generics with bounds
> (e.g. `T: Clone, const N: usize`)
> - `decl_generics`: the generics with bounds and default values
> (e.g. `T: Clone, const N: usize = 0`)
> - `ty_generics`: contains the generics without bounds and without
> default values (e.g. `T, N`)
>
> `impl_generics` is designed to be used on `impl<$impl_generics>`,
> `decl_generics` for the type definition, so `struct Foo<$decl_generics>`
> and `ty_generics` whenever you use the type, so `Foo<$ty_generics>`.
>
> Here is an example that uses all three different types of generics:
>
> let (Generics { decl_generics, impl_generics, ty_generics }, rest) = parse_generics(input);
> quote! {
> struct Foo<$($decl_generics)*> {
> // ...
> }
>
> impl<$impl_generics> Foo<$ty_generics> {
> fn foo() {
> // ...
> }
> }
> }
>
> The next commit contains a fix to the `#[pin_data]` macro making it
> compatible with generic parameter default values by relying on this new
> behavior.
>
> Signed-off-by: Benno Lossin <benno.lossin@proton.me>
> ---
> [...]
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
next prev parent reply other threads:[~2023-12-14 3:13 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
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 ` Martin Rodriguez Reboredo [this message]
2023-12-23 14:41 ` [PATCH v2 1/3] rust: macros: add `decl_generics` to `parse_generics()` 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=f9b8f95e-1e72-4907-9964-6a4ecfc435b1@gmail.com \
--to=yakoyoku@gmail.com \
--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=gary@garyguo.net \
--cc=lina@asahilina.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sylphrenadin@gmail.com \
--cc=vincenzopalazzodev@gmail.com \
--cc=wedsonaf@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;
as well as URLs for NNTP newsgroup(s).