Skip to content

Commit b948896

Browse files
committed
rust: pin-init: rewrite #[pin_data] using syn
Rewrite the attribute macro `#[pin_data]` using `syn`. No functional changes intended aside from improved error messages on syntactic and semantical errors. For example if one forgets a comma at the end of a field: #[pin_data] struct Foo { a: Box<Foo> b: Box<Foo> } The declarative macro reports the following errors: error: expected `,`, or `}`, found `b` --> tests/ui/compile-fail/pin_data/missing_comma.rs:5:16 | 5 | a: Box<Foo> | ^ help: try adding a comma: `,` error: recursion limit reached while expanding `$crate::__pin_data!` --> tests/ui/compile-fail/pin_data/missing_comma.rs:3:1 | 3 | #[pin_data] | ^^^^^^^^^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`$CRATE`) = note: this error originates in the macro `$crate::__pin_data` which comes from the expansion of the attribute macro `pin_data` (in Nightly builds, run with -Z macro-backtrace for more info) The new `syn` version reports: error: expected `,`, or `}`, found `b` --> tests/ui/compile-fail/pin_data/missing_comma.rs:5:16 | 5 | a: Box<Foo> | ^ help: try adding a comma: `,` error: expected `,` --> tests/ui/compile-fail/pin_data/missing_comma.rs:6:5 | 6 | b: Box<Foo> | ^ Signed-off-by: Benno Lossin <lossin@kernel.org>
1 parent d72b229 commit b948896

4 files changed

Lines changed: 523 additions & 838 deletions

File tree

rust/pin-init/internal/src/helpers.rs

Lines changed: 0 additions & 149 deletions
This file was deleted.

rust/pin-init/internal/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
use proc_macro::TokenStream;
1414
use syn::parse_macro_input;
1515

16-
mod helpers;
1716
mod pin_data;
1817
mod pinned_drop;
1918
mod zeroable;
2019

2120
#[proc_macro_attribute]
22-
pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
23-
pin_data::pin_data(inner.into(), item.into()).into()
21+
pub fn pin_data(args: TokenStream, input: TokenStream) -> TokenStream {
22+
ok_or_compile_error(pin_data::pin_data(
23+
parse_macro_input!(args),
24+
parse_macro_input!(input),
25+
))
2426
}
2527

2628
#[proc_macro_attribute]

0 commit comments

Comments
 (0)