lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f9b8f95e-1e72-4907-9964-6a4ecfc435b1@gmail.com>
Date:   Wed, 13 Dec 2023 23:57:29 -0300
From:   Martin Rodriguez Reboredo <yakoyoku@...il.com>
To:     Benno Lossin <benno.lossin@...ton.me>,
        Miguel Ojeda <ojeda@...nel.org>,
        Alex Gaynor <alex.gaynor@...il.com>,
        Wedson Almeida Filho <wedsonaf@...il.com>,
        Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
        Björn Roy Baron <bjorn3_gh@...tonmail.com>,
        Andreas Hindborg <a.hindborg@...sung.com>,
        Alice Ryhl <aliceryhl@...gle.com>,
        Sumera Priyadarsini <sylphrenadin@...il.com>,
        Vincenzo Palazzo <vincenzopalazzodev@...il.com>,
        Asahi Lina <lina@...hilina.net>
Cc:     rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/3] rust: macros: add `decl_generics` to
 `parse_generics()`

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@...ton.me>
> ---
> [...]

Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@...il.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ