public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8613] gccrs: Handle `async` functions in traits
@ 2024-01-30 12:01 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-30 12:01 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f46fdb6399d91d56f095088c8cf0f1fd6d971e25
commit r14-8613-gf46fdb6399d91d56f095088c8cf0f1fd6d971e25
Author: Kushal Pal <kushalpal109@gmail.com>
Date: Wed Jan 3 16:02:07 2024 +0530
gccrs: Handle `async` functions in traits
Fixes #2785
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Added check for `async` functions inside trait.
* parse/rust-parse-impl.h (Parser::parse_trait_item):
Added switch-case for ASYNC token.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2785.rs: New test.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Diff:
---
gcc/rust/checks/errors/rust-ast-validation.cc | 13 ++++++++++---
gcc/rust/parse/rust-parse-impl.h | 1 +
gcc/testsuite/rust/compile/issue-2785.rs | 9 +++++++++
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc
index b50e9cdf8581..0ed5d0608943 100644
--- a/gcc/rust/checks/errors/rust-ast-validation.cc
+++ b/gcc/rust/checks/errors/rust-ast-validation.cc
@@ -141,9 +141,16 @@ ASTValidation::visit (AST::TraitFunctionDecl &decl)
{
const auto &qualifiers = decl.get_qualifiers ();
- if (context.back () == Context::TRAIT && qualifiers.is_const ())
- rust_error_at (decl.get_identifier ().get_locus (), ErrorCode::E0379,
- "functions in traits cannot be declared const");
+ if (context.back () == Context::TRAIT)
+ {
+ // may change soon
+ if (qualifiers.is_async ())
+ rust_error_at (decl.get_identifier ().get_locus (), ErrorCode::E0706,
+ "functions in traits cannot be declared %<async%>");
+ if (qualifiers.is_const ())
+ rust_error_at (decl.get_identifier ().get_locus (), ErrorCode::E0379,
+ "functions in traits cannot be declared const");
+ }
}
void
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index dfa2762c5c3e..3055a3959cff 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -5096,6 +5096,7 @@ Parser<ManagedTokenSource>::parse_trait_item ()
// else, fallthrough to function
// TODO: find out how to disable gcc "implicit fallthrough" error
gcc_fallthrough ();
+ case ASYNC:
case UNSAFE:
case EXTERN_KW:
case FN_KW: {
diff --git a/gcc/testsuite/rust/compile/issue-2785.rs b/gcc/testsuite/rust/compile/issue-2785.rs
new file mode 100644
index 000000000000..08f6346f60b2
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2785.rs
@@ -0,0 +1,9 @@
+// { dg-additional-options "-frust-edition=2018" }
+trait Foo {
+ async fn foo(){}
+ // { dg-error "functions in traits cannot be declared .async." "" { target *-*-* } .-1 }
+ async fn bar();
+ // { dg-error "functions in traits cannot be declared .async." "" { target *-*-* } .-1 }
+}
+
+fn main() {}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-30 12:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 12:01 [gcc r14-8613] gccrs: Handle `async` functions in traits Arthur Cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).