aboutsummaryrefslogtreecommitdiff
path: root/cortex-m-rt/macros
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2018-09-19 23:41:59 +0200
committerGravatar Jorge Aparicio <jorge@japaric.io> 2018-09-19 23:41:59 +0200
commit7f7138a62f9efdf9057cc4ec01733e448ecce55b (patch)
treec3aad33ebc6248baf017e06d5ac2e012a85f8ac9 /cortex-m-rt/macros
parent44b04a356d74fd804eab98579b3622dedbdadd46 (diff)
downloadcortex-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')
-rw-r--r--cortex-m-rt/macros/Cargo.toml6
-rw-r--r--cortex-m-rt/macros/src/lib.rs7
2 files changed, 7 insertions, 6 deletions
diff --git a/cortex-m-rt/macros/Cargo.toml b/cortex-m-rt/macros/Cargo.toml
index 8d7e517..eded8bf 100644
--- a/cortex-m-rt/macros/Cargo.toml
+++ b/cortex-m-rt/macros/Cargo.toml
@@ -13,12 +13,12 @@ version = "0.1.1"
proc-macro = true
[dependencies]
-quote = "0.6.6"
-proc-macro2 = "0.4.15"
+quote = "0.6.8"
+proc-macro2 = "0.4.19"
[dependencies.syn]
features = ["extra-traits", "full"]
-version = "0.14.8"
+version = "0.15.4"
[dependencies.rand]
version = "0.5.5"
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!(