Skip to content

WIP: parse swapped pub and async #59395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6489,6 +6489,11 @@ impl<'a> Parser<'a> {
at_end: &mut bool,
mut attrs: Vec<Attribute>) -> 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() {
Expand All @@ -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)
};
Expand Down
8 changes: 1 addition & 7 deletions src/test/ui/editions/edition-deny-async-fns-2015.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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`.
2 changes: 2 additions & 0 deletions src/test/ui/parser/swapped-pub-async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// doc comment
async pub fn foo() -> impl Future<..> {}
8 changes: 8 additions & 0 deletions src/test/ui/parser/swapped-pub-async.stderr
Original file line number Diff line number Diff line change
@@ -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