diff options
author | Kushal Pal <kushalpal109@gmail.com> | 2023-12-16 20:07:23 +0530 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-30 12:36:50 +0100 |
commit | 81fcf1087ccaa83088aaed8b8be9777e66d2465d (patch) | |
tree | 3391f874b98be6bf07eb497600884f14eb8a110c /gcc | |
parent | bffceda8b9a80f4a4cea28b4e42e13ffb07264c7 (diff) | |
download | gcc-81fcf1087ccaa83088aaed8b8be9777e66d2465d.zip gcc-81fcf1087ccaa83088aaed8b8be9777e66d2465d.tar.gz gcc-81fcf1087ccaa83088aaed8b8be9777e66d2465d.tar.bz2 |
gccrs: Generate error for `async` trait fucntions
Fixes #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>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/checks/errors/rust-ast-validation.cc | 5 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-2767.rs | 13 |
2 files changed, 18 insertions, 0 deletions
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index cd197fc..b50e9cd 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -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 ( diff --git a/gcc/testsuite/rust/compile/issue-2767.rs b/gcc/testsuite/rust/compile/issue-2767.rs new file mode 100644 index 0000000..9e7e0f9 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2767.rs @@ -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() {} |