Skip to content

Commit 560f6d1

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> | ^ Tested-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Benno Lossin <lossin@kernel.org>
1 parent a92f5fd commit 560f6d1

4 files changed

Lines changed: 503 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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ use syn::parse_macro_input;
1616
use crate::diagnostics::DiagCtxt;
1717

1818
mod diagnostics;
19-
mod helpers;
2019
mod pin_data;
2120
mod pinned_drop;
2221
mod zeroable;
2322

2423
#[proc_macro_attribute]
25-
pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
26-
pin_data::pin_data(inner.into(), item.into()).into()
24+
pub fn pin_data(args: TokenStream, input: TokenStream) -> TokenStream {
25+
let args = parse_macro_input!(args);
26+
let input = parse_macro_input!(input);
27+
DiagCtxt::with(|dcx| pin_data::pin_data(args, input, dcx)).into()
2728
}
2829

2930
#[proc_macro_attribute]

0 commit comments

Comments
 (0)