Skip to content

Commit

Permalink
Generate error for async trait fucntions
Browse files Browse the repository at this point in the history
Fixes Rust-GCC#2767

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
	Added check for `async` function inside trait.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
  • Loading branch information
braw-lee committed Dec 27, 2023
1 parent 7cb0591 commit 4c00228
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gcc/rust/checks/errors/rust-ast-validation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ ASTValidation::visit (AST::Function &function)
rust_error_at (function.get_locus (), ErrorCode::E0379,
"functions in traits cannot be declared const");

// may change soon
if (qualifiers.is_async () && context.back () == Context::TRAIT_IMPL)
rust_error_at (function.get_locus (), ErrorCode::E0706,
"functions in traits cannot be declared %<async%>");

if (valid_context.find (context.back ()) == valid_context.end ()
&& function.has_self_param ())
rust_error_at (
Expand Down
13 changes: 13 additions & 0 deletions gcc/testsuite/rust/compile/issue-2767.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// { dg-additional-options "-frust-edition=2018" }
trait Foo {
fn f() -> u32;
}

impl Foo for u32 {
async fn f() -> u32 {
// { dg-error "functions in traits cannot be declared .async." "" { target *-*-* } .-1 }
22
}
}

fn main() {}

0 comments on commit 4c00228

Please sign in to comment.