Async functions and methods
diff --git a/src/gen/fold.rs b/src/gen/fold.rs
index 2499daf..f73e64d 100644
--- a/src/gen/fold.rs
+++ b/src/gen/fold.rs
@@ -1996,6 +1996,7 @@
vis: _visitor.fold_visibility(_i.vis),
constness: (_i.constness).map(|it| Token ! [ const ](tokens_helper(_visitor, &it.span))),
unsafety: (_i.unsafety).map(|it| Token ! [ unsafe ](tokens_helper(_visitor, &it.span))),
+ asyncness: (_i.asyncness).map(|it| Token)),
abi: (_i.abi).map(|it| _visitor.fold_abi(it)),
ident: _visitor.fold_ident(_i.ident),
decl: Box::new(_visitor.fold_fn_decl(*_i.decl)),
@@ -2290,6 +2291,7 @@
MethodSig {
constness: (_i.constness).map(|it| Token ! [ const ](tokens_helper(_visitor, &it.span))),
unsafety: (_i.unsafety).map(|it| Token ! [ unsafe ](tokens_helper(_visitor, &it.span))),
+ asyncness: (_i.asyncness).map(|it| Token)),
abi: (_i.abi).map(|it| _visitor.fold_abi(it)),
ident: _visitor.fold_ident(_i.ident),
decl: _visitor.fold_fn_decl(_i.decl),
diff --git a/src/gen/visit.rs b/src/gen/visit.rs
index e2b2ba0..f3015be 100644
--- a/src/gen/visit.rs
+++ b/src/gen/visit.rs
@@ -2221,6 +2221,9 @@
if let Some(ref it) = _i.unsafety {
tokens_helper(_visitor, &it.span)
};
+ if let Some(ref it) = _i.asyncness {
+ tokens_helper(_visitor, &it.span)
+ };
if let Some(ref it) = _i.abi {
_visitor.visit_abi(it)
};
@@ -2597,6 +2600,9 @@
if let Some(ref it) = _i.unsafety {
tokens_helper(_visitor, &it.span)
};
+ if let Some(ref it) = _i.asyncness {
+ tokens_helper(_visitor, &it.span)
+ };
if let Some(ref it) = _i.abi {
_visitor.visit_abi(it)
};
diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs
index 6bcc837..6f61765 100644
--- a/src/gen/visit_mut.rs
+++ b/src/gen/visit_mut.rs
@@ -2180,6 +2180,9 @@
if let Some(ref mut it) = _i.unsafety {
tokens_helper(_visitor, &mut it.span)
};
+ if let Some(ref mut it) = _i.asyncness {
+ tokens_helper(_visitor, &mut it.span)
+ };
if let Some(ref mut it) = _i.abi {
_visitor.visit_abi_mut(it)
};
@@ -2544,6 +2547,9 @@
if let Some(ref mut it) = _i.unsafety {
tokens_helper(_visitor, &mut it.span)
};
+ if let Some(ref mut it) = _i.asyncness {
+ tokens_helper(_visitor, &mut it.span)
+ };
if let Some(ref mut it) = _i.abi {
_visitor.visit_abi_mut(it)
};
diff --git a/src/item.rs b/src/item.rs
index ffbd606..09469b5 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -93,6 +93,7 @@
pub vis: Visibility,
pub constness: Option<Token![const]>,
pub unsafety: Option<Token![unsafe]>,
+ pub asyncness: Option<Token![async]>,
pub abi: Option<Abi>,
pub ident: Ident,
pub decl: Box<FnDecl>,
@@ -652,6 +653,7 @@
pub struct MethodSig {
pub constness: Option<Token![const]>,
pub unsafety: Option<Token![unsafe]>,
+ pub asyncness: Option<Token![async]>,
pub abi: Option<Abi>,
pub ident: Ident,
pub decl: FnDecl,
@@ -736,8 +738,6 @@
|
syn!(ItemFn) => { Item::Fn }
|
- call!(unstable_async_fn) => { Item::Verbatim }
- |
syn!(ItemMod) => { Item::Mod }
|
syn!(ItemForeignMod) => { Item::ForeignMod }
@@ -958,6 +958,7 @@
vis: syn!(Visibility) >>
constness: option!(keyword!(const)) >>
unsafety: option!(keyword!(unsafe)) >>
+ asyncness: option!(keyword!(async)) >>
abi: option!(syn!(Abi)) >>
fn_: keyword!(fn) >>
ident: syn!(Ident) >>
@@ -978,6 +979,7 @@
vis: vis,
constness: constness,
unsafety: unsafety,
+ asyncness: asyncness,
abi: abi,
decl: Box::new(FnDecl {
fn_token: fn_,
@@ -998,30 +1000,6 @@
})
));
- named!(unstable_async_fn -> ItemVerbatim, do_parse!(
- begin: call!(verbatim::grab_cursor) >>
- many0!(Attribute::parse_outer) >>
- syn!(Visibility) >>
- option!(keyword!(const)) >>
- option!(keyword!(unsafe)) >>
- keyword!(async) >>
- option!(syn!(Abi)) >>
- keyword!(fn) >>
- syn!(Ident) >>
- syn!(Generics) >>
- parens!(Punctuated::<FnArg, Token![,]>::parse_terminated) >>
- syn!(ReturnType) >>
- option!(syn!(WhereClause)) >>
- braces!(tuple!(
- many0!(Attribute::parse_inner),
- call!(Block::parse_within),
- )) >>
- end: call!(verbatim::grab_cursor) >>
- (ItemVerbatim {
- tts: verbatim::token_range(begin..end),
- })
- ));
-
impl Synom for FnArg {
named!(parse -> Self, alt!(
do_parse!(
@@ -1391,6 +1369,7 @@
sig: MethodSig {
constness: constness,
unsafety: unsafety,
+ asyncness: None,
abi: abi,
ident: ident,
decl: FnDecl {
@@ -1504,8 +1483,6 @@
|
syn!(ImplItemMethod) => { ImplItem::Method }
|
- call!(unstable_async_method) => { ImplItem::Verbatim }
- |
syn!(ImplItemType) => { ImplItem::Type }
|
call!(unstable_impl_existential_type) => { ImplItem::Verbatim }
@@ -1544,6 +1521,7 @@
defaultness: option!(keyword!(default)) >>
constness: option!(keyword!(const)) >>
unsafety: option!(keyword!(unsafe)) >>
+ asyncness: option!(keyword!(async)) >>
abi: option!(syn!(Abi)) >>
fn_: keyword!(fn) >>
ident: syn!(Ident) >>
@@ -1566,6 +1544,7 @@
sig: MethodSig {
constness: constness,
unsafety: unsafety,
+ asyncness: asyncness,
abi: abi,
ident: ident,
decl: FnDecl {
@@ -1587,31 +1566,6 @@
})
));
- named!(unstable_async_method -> ImplItemVerbatim, do_parse!(
- begin: call!(verbatim::grab_cursor) >>
- many0!(Attribute::parse_outer) >>
- syn!(Visibility) >>
- option!(keyword!(default)) >>
- option!(keyword!(const)) >>
- option!(keyword!(unsafe)) >>
- keyword!(async) >>
- option!(syn!(Abi)) >>
- keyword!(fn) >>
- syn!(Ident) >>
- syn!(Generics) >>
- parens!(Punctuated::<FnArg, Token![,]>::parse_terminated) >>
- syn!(ReturnType) >>
- option!(syn!(WhereClause)) >>
- braces!(tuple!(
- many0!(Attribute::parse_inner),
- call!(Block::parse_within),
- )) >>
- end: call!(verbatim::grab_cursor) >>
- (ImplItemVerbatim {
- tts: verbatim::token_range(begin..end),
- })
- ));
-
impl_synom!(ImplItemType "type in impl block" do_parse!(
attrs: many0!(Attribute::parse_outer) >>
vis: syn!(Visibility) >>
@@ -1731,6 +1685,7 @@
self.vis.to_tokens(tokens);
self.constness.to_tokens(tokens);
self.unsafety.to_tokens(tokens);
+ self.asyncness.to_tokens(tokens);
self.abi.to_tokens(tokens);
NamedDecl(&self.decl, &self.ident).to_tokens(tokens);
self.block.brace_token.surround(tokens, |tokens| {
@@ -2125,6 +2080,7 @@
fn to_tokens(&self, tokens: &mut TokenStream) {
self.constness.to_tokens(tokens);
self.unsafety.to_tokens(tokens);
+ self.asyncness.to_tokens(tokens);
self.abi.to_tokens(tokens);
NamedDecl(&self.decl, &self.ident).to_tokens(tokens);
}
diff --git a/tests/test_async_fn.rs b/tests/test_async_fn.rs
new file mode 100644
index 0000000..b01d6b6
--- /dev/null
+++ b/tests/test_async_fn.rs
@@ -0,0 +1,45 @@
+// Copyright 2018 Syn Developers
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![cfg(all(feature = "extra-traits", feature = "full"))]
+
+extern crate proc_macro2;
+extern crate syn;
+
+use proc_macro2::Span;
+use syn::{Block, FnDecl, Ident, ItemFn, ReturnType, Visibility};
+use syn::punctuated::Punctuated;
+
+#[test]
+fn test_async_fn() {
+ let raw = "async fn process() {}";
+
+ let expected = ItemFn {
+ attrs: vec![],
+ vis: Visibility::Inherited,
+ constness: None,
+ unsafety: None,
+ asyncness: Some(Default::default()),
+ abi: None,
+ ident: Ident::new("process", Span::call_site()),
+ decl: Box::new(FnDecl {
+ fn_token: Default::default(),
+ generics: Default::default(),
+ paren_token: Default::default(),
+ inputs: Punctuated::new(),
+ variadic: None,
+ output: ReturnType::Default,
+ }),
+ block: Box::new(Block {
+ brace_token: Default::default(),
+ stmts: vec![],
+ }),
+ };
+
+ assert_eq!(expected, syn::parse_str(raw).unwrap());
+}