]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Generate error for `async` trait fucntions
authorKushal Pal <kushalpal109@gmail.com>
Sat, 16 Dec 2023 14:37:23 +0000 (20:07 +0530)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 30 Jan 2024 11:36:50 +0000 (12:36 +0100)
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>
gcc/rust/checks/errors/rust-ast-validation.cc
gcc/testsuite/rust/compile/issue-2767.rs [new file with mode: 0644]

index cd197fc1ea7d9c87615d369b4689626ba5593282..b50e9cdf8581b8c3e67c190be38b1c1d60c48d09 100644 (file)
@@ -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 (file)
index 0000000..9e7e0f9
--- /dev/null
@@ -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() {}