diff options
author | 2018-09-19 23:41:59 +0200 | |
---|---|---|
committer | 2018-09-19 23:41:59 +0200 | |
commit | 7f7138a62f9efdf9057cc4ec01733e448ecce55b (patch) | |
tree | c3aad33ebc6248baf017e06d5ac2e012a85f8ac9 /cortex-m-rt/macros/src | |
parent | 44b04a356d74fd804eab98579b3622dedbdadd46 (diff) | |
download | cortex-m-7f7138a62f9efdf9057cc4ec01733e448ecce55b.tar.gz cortex-m-7f7138a62f9efdf9057cc4ec01733e448ecce55b.tar.zst cortex-m-7f7138a62f9efdf9057cc4ec01733e448ecce55b.zip |
bump the syn dependency
and switch to the recommended way to parse tokens: `parse_macro_input!`.
This improves (?) error messages when the user applies one of our attributes to
an item that's not a function.
Consider
``` rust
#[entry]
static MAIN: () = ();
```
The error message changed from:
```
error: custom attribute panicked
--> src/main.rs:10:1
|
10 | #[entry]
| ^^^^^^^^
|
= help: message: `#[entry]` must be applied to a function: ParseError(Some("failed to parse fn item: failed to parse"))
```
to:
```
error: expected `fn`
--> src/main.rs:11:1
|
11 | static MAIN: () = ();
| ^^^^^^
error: aborting due to previous error
```
Diffstat (limited to 'cortex-m-rt/macros/src')
-rw-r--r-- | cortex-m-rt/macros/src/lib.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs index 804dd64..f9ae17e 100644 --- a/cortex-m-rt/macros/src/lib.rs +++ b/cortex-m-rt/macros/src/lib.rs @@ -6,6 +6,7 @@ extern crate rand; extern crate quote; extern crate core; extern crate proc_macro2; +#[macro_use] extern crate syn; use proc_macro2::Span; @@ -77,7 +78,7 @@ use proc_macro::TokenStream; /// ``` #[proc_macro_attribute] pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { - let f: ItemFn = syn::parse(input).expect("`#[entry]` must be applied to a function"); + let f = parse_macro_input!(input as ItemFn); // check the function signature assert!( @@ -253,7 +254,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { /// ``` #[proc_macro_attribute] pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { - let f: ItemFn = syn::parse(input).expect("`#[exception]` must be applied to a function"); + let f = parse_macro_input!(input as ItemFn); assert!( args.to_string() == "", @@ -459,7 +460,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { /// ``` #[proc_macro_attribute] pub fn pre_init(args: TokenStream, input: TokenStream) -> TokenStream { - let f: ItemFn = syn::parse(input).expect("`#[pre_init]` must be applied to a function"); + let f = parse_macro_input!(input as ItemFn); // check the function signature assert!( |