linux/rust
Benno Lossin 22eed6068d rust: macros: allow generic parameter default values in #[pin_data]
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: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Tested-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240309155243.482334-2-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-04-07 22:03:42 +02:00
..
alloc rust: upgrade to Rust 1.77.1 2024-03-29 20:12:30 +01:00
bindings rust: bindings: Order headers alphabetically 2024-02-18 21:21:48 +01:00
kernel rust: macros: allow generic parameter default values in #[pin_data] 2024-04-07 22:03:42 +02:00
macros rust: macros: allow generic parameter default values in #[pin_data] 2024-04-07 22:03:42 +02:00
uapi net: phy: add Rust Asix PHY driver 2023-12-15 09:35:50 +00:00
.gitignore rust: support running Rust documentation tests as KUnit ones 2023-07-19 09:32:53 -06:00
bindgen_parameters rust: Ignore preserve-most functions 2023-12-13 01:09:55 +01:00
build_error.rs rust: add build_error crate 2022-12-04 01:59:16 +01:00
compiler_builtins.rs rust: upgrade to Rust 1.73.0 2023-10-15 21:25:08 +02:00
exports.c rust: replace <linux/module.h> with <linux/export.h> in rust/exports.c 2023-12-13 01:09:55 +01:00
helpers.c rust: workqueue: add helper for defining work_struct fields 2023-09-25 09:46:42 -10:00
Makefile Kbuild updates for v6.9 2024-03-21 14:41:00 -07:00