Skip to content

Commit 651a5fd

Browse files
committed
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 <[email protected]>
1 parent bfabc61 commit 651a5fd

17 files changed

+707
-980
lines changed

internal/src/helpers.rs

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

internal/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
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+
pin_data::pin_data(
23+
parse_macro_input!(args as _),
24+
parse_macro_input!(input as _),
25+
)
26+
.into()
2427
}
2528

2629
#[proc_macro_attribute]

0 commit comments

Comments
 (0)