Skip to content

Commit

Permalink
Handle async functions declarations in traits
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_trait_item):
	Add switch-case for ASYNC token.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2785.rs: New test.

Signed-off-by: Kushal Pal <[email protected]>
  • Loading branch information
braw-lee committed Jan 3, 2024
1 parent a12143b commit 9c67db4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5087,6 +5087,11 @@ Parser<ManagedTokenSource>::parse_trait_item ()
{
case TYPE:
return parse_trait_type (std::move (outer_attrs), vis);
// may need to implement `parse_trait_async()`
case ASYNC:
add_error (Error (tok->get_locus (),
"functions in traits cannot be declared %<async%>"));
return nullptr;
case CONST:
// disambiguate with function qualifier
if (lexer.peek_token (1)->get_id () == IDENTIFIER)
Expand Down
7 changes: 7 additions & 0 deletions gcc/testsuite/rust/compile/issue-2785.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// { dg-additional-options "-frust-edition=2018" }

Check failure on line 1 in gcc/testsuite/rust/compile/issue-2785.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-32bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/issue-2785.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit

Test failure (FAIL)

(test for excess errors)
trait Foo {
async fn foo();
// { dg-error "functions in traits cannot be declared .async." "" { target *-*-* } .-1 }
}

fn main() {}

0 comments on commit 9c67db4

Please sign in to comment.