diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 3e00d948c1aa8..eda3fadff0967 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6489,6 +6489,11 @@ impl<'a> Parser<'a> { at_end: &mut bool, mut attrs: Vec) -> PResult<'a, ImplItem> { let lo = self.span; + let mut is_async = false; + if self.eat_keyword(keywords::Async) && self.span.rust_2018() { + self.span_err(self.span, "hoge"); + is_async = true; + } let vis = self.parse_visibility(false)?; let defaultness = self.parse_defaultness(); let (name, node, generics) = if let Some(type_) = self.eat_type() { @@ -6510,7 +6515,17 @@ impl<'a> Parser<'a> { self.expect(&token::Semi)?; (name, ast::ImplItemKind::Const(typ, expr), ast::Generics::default()) } else { - let (name, inner_attrs, generics, node) = self.parse_impl_method(&vis, at_end)?; + let (name, inner_attrs, generics, mut node) = self.parse_impl_method(&vis, at_end)?; + if is_async { + let (constness, unsafety, asyncness, abi) = self.parse_fn_front_matter()?; + let decl = self.parse_fn_decl_with_self(|p| p.parse_arg())?; + let header = ast::FnHeader { abi, unsafety, constness, asyncness }; + let (_, body) = self.parse_inner_attrs_and_block()?; + node = ast::ImplItemKind::Method( + ast::MethodSig { header, decl }, + body + ); + } attrs.extend(inner_attrs); (name, node, generics) }; diff --git a/src/test/ui/editions/edition-deny-async-fns-2015.stderr b/src/test/ui/editions/edition-deny-async-fns-2015.stderr index 83c8dbc7472fd..59d9adf0c8541 100644 --- a/src/test/ui/editions/edition-deny-async-fns-2015.stderr +++ b/src/test/ui/editions/edition-deny-async-fns-2015.stderr @@ -34,12 +34,6 @@ error[E0670]: `async fn` is not permitted in the 2015 edition LL | async fn foo() {} | ^^^^^ -error[E0670]: `async fn` is not permitted in the 2015 edition - --> $DIR/edition-deny-async-fns-2015.rs:16:5 - | -LL | async fn foo() {} - | ^^^^^ - error[E0706]: trait fns cannot be declared `async` --> $DIR/edition-deny-async-fns-2015.rs:20:5 | @@ -52,7 +46,7 @@ error[E0670]: `async fn` is not permitted in the 2015 edition LL | async fn foo() {} | ^^^^^ -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors Some errors occurred: E0670, E0706. For more information about an error, try `rustc --explain E0670`. diff --git a/src/test/ui/parser/swapped-pub-async.rs b/src/test/ui/parser/swapped-pub-async.rs new file mode 100644 index 0000000000000..4d49137ce455d --- /dev/null +++ b/src/test/ui/parser/swapped-pub-async.rs @@ -0,0 +1,2 @@ +/// doc comment +async pub fn foo() -> impl Future<..> {} diff --git a/src/test/ui/parser/swapped-pub-async.stderr b/src/test/ui/parser/swapped-pub-async.stderr new file mode 100644 index 0000000000000..81811cb63ad5b --- /dev/null +++ b/src/test/ui/parser/swapped-pub-async.stderr @@ -0,0 +1,8 @@ +error: expected one of `!` or `::`, found `pub` + --> $DIR/swapped-pub-async.rs:2:7 + | +LL | async pub fn foo() -> impl Future<..> {} + | ^^^ expected one of `!` or `::` here + +error: aborting due to previous error +