Commit 7e49a09
rust: macros: allow generic parameter default values in
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#[pin_data]
1 parent 46a8106 commit 7e49a09
3 files changed
Lines changed: 20 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
| 541 | + | |
541 | 542 | | |
542 | 543 | | |
543 | 544 | | |
| |||
560 | 561 | | |
561 | 562 | | |
562 | 563 | | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
563 | 567 | | |
564 | 568 | | |
565 | 569 | | |
| |||
585 | 589 | | |
586 | 590 | | |
587 | 591 | | |
| 592 | + | |
588 | 593 | | |
589 | 594 | | |
590 | 595 | | |
| |||
607 | 612 | | |
608 | 613 | | |
609 | 614 | | |
| 615 | + | |
610 | 616 | | |
611 | 617 | | |
612 | 618 | | |
| |||
623 | 629 | | |
624 | 630 | | |
625 | 631 | | |
| 632 | + | |
626 | 633 | | |
627 | 634 | | |
628 | 635 | | |
| |||
640 | 647 | | |
641 | 648 | | |
642 | 649 | | |
| 650 | + | |
643 | 651 | | |
644 | 652 | | |
645 | 653 | | |
| |||
656 | 664 | | |
657 | 665 | | |
658 | 666 | | |
| 667 | + | |
659 | 668 | | |
660 | 669 | | |
661 | 670 | | |
| |||
673 | 682 | | |
674 | 683 | | |
675 | 684 | | |
| 685 | + | |
676 | 686 | | |
677 | 687 | | |
678 | 688 | | |
| |||
689 | 699 | | |
690 | 700 | | |
691 | 701 | | |
| 702 | + | |
692 | 703 | | |
693 | 704 | | |
694 | 705 | | |
| |||
705 | 716 | | |
706 | 717 | | |
707 | 718 | | |
| 719 | + | |
708 | 720 | | |
709 | 721 | | |
710 | 722 | | |
| |||
724 | 736 | | |
725 | 737 | | |
726 | 738 | | |
| 739 | + | |
727 | 740 | | |
728 | 741 | | |
729 | 742 | | |
| |||
741 | 754 | | |
742 | 755 | | |
743 | 756 | | |
| 757 | + | |
744 | 758 | | |
745 | 759 | | |
746 | 760 | | |
| |||
757 | 771 | | |
758 | 772 | | |
759 | 773 | | |
| 774 | + | |
760 | 775 | | |
761 | 776 | | |
762 | 777 | | |
| |||
773 | 788 | | |
774 | 789 | | |
775 | 790 | | |
| 791 | + | |
776 | 792 | | |
777 | 793 | | |
778 | 794 | | |
| |||
789 | 805 | | |
790 | 806 | | |
791 | 807 | | |
| 808 | + | |
792 | 809 | | |
793 | 810 | | |
794 | 811 | | |
| |||
802 | 819 | | |
803 | 820 | | |
804 | 821 | | |
805 | | - | |
| 822 | + | |
806 | 823 | | |
807 | 824 | | |
808 | 825 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
0 commit comments