Commit 5d4eb2d
committed
rust: macros: rewrite
Now that `syn` and `quote` are available in the Kernel use them for the
`__internal_init!` macro instead of the current hybrid
proc-macro/declarative approach.
Note that the new macro is called `primitive_init!`.
Proc-macros written using `syn` are a lot more readable and thus easier
to maintain than convoluted declarative macros. An additional advantage
of `syn` is the improved error reporting, here is an example:
When adding an additional `,` at the end of `..Zeroable::zeroed()`
pin_init!(Foo {
a: Bar,
b <- Bar,
c: Bar,
d: Bar,
..Zeroable::zeroed(),
// ^ this is the culprit!
})
Prior to this patch, the error reads:
error: no rules expected the token `,`
--> samples/rust/rust_minimal.rs:51:5
|
51 | / pin_init!(Foo {
52 | | a: Bar,
53 | | b <- Bar,
54 | | c: Bar,
55 | | d: Bar,
56 | | ..Zeroable::zeroed(),
57 | | })
| |______^ no rules expected this token in macro call
|
note: while trying to match `)`
--> rust/kernel/init/macros.rs:1169:53
|
1169 | @munch_fields($(..Zeroable::zeroed())? $(,)?),
| ^
= note: this error originates in the macro `$crate::__init_internal` which comes from the expansion of the macro `pin_init` (in Nightly builds, run with -Z macro-backtrace for more info)
error: no rules expected the token `,`
--> samples/rust/rust_minimal.rs:51:5
|
51 | / pin_init!(Foo {
52 | | a: Bar,
53 | | b <- Bar,
54 | | c: Bar,
55 | | d: Bar,
56 | | ..Zeroable::zeroed(),
57 | | })
| |______^ no rules expected this token in macro call
|
note: while trying to match `)`
--> rust/kernel/init/macros.rs:1273:49
|
1273 | @munch_fields(..Zeroable::zeroed() $(,)?),
| ^
= note: this error originates in the macro `$crate::__init_internal` which comes from the expansion of the macro `pin_init` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
After this patch, the error reads:
error: unexpected token
--> samples/rust/rust_minimal.rs:56:29
|
56 | ..Zeroable::zeroed(),
| ^
error: aborting due to 1 previous error
Signed-off-by: Benno Lossin <[email protected]>__internal_init! using syn
1 parent b8459ad commit 5d4eb2d
File tree
4 files changed
+418
-410
lines changed- rust
- kernel
- init
- macros
4 files changed
+418
-410
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
557 | 557 | | |
558 | 558 | | |
559 | 559 | | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
570 | 563 | | |
571 | 564 | | |
572 | 565 | | |
| |||
614 | 607 | | |
615 | 608 | | |
616 | 609 | | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
627 | 613 | | |
628 | 614 | | |
629 | 615 | | |
630 | 616 | | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
641 | 620 | | |
642 | 621 | | |
643 | 622 | | |
| |||
663 | 642 | | |
664 | 643 | | |
665 | 644 | | |
666 | | - | |
667 | | - | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
676 | 648 | | |
677 | 649 | | |
678 | 650 | | |
| |||
714 | 686 | | |
715 | 687 | | |
716 | 688 | | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
727 | 692 | | |
728 | 693 | | |
729 | 694 | | |
730 | 695 | | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | | - | |
739 | | - | |
740 | | - | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
741 | 699 | | |
742 | 700 | | |
743 | 701 | | |
| |||
0 commit comments