You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
0 commit comments