[COMMITTED 053/101] gccrs: Add async const function ast validation pass

arthur.cohen@embecosm.com arthur.cohen@embecosm.com
Tue Jan 30 12:07:09 GMT 2024


From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Add a check during AST validation pass to ensure functions are either
const or async but not both.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
	async const check.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
 gcc/rust/checks/errors/rust-ast-validation.cc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc
index 4b209908f9e..54276e8fd59 100644
--- a/gcc/rust/checks/errors/rust-ast-validation.cc
+++ b/gcc/rust/checks/errors/rust-ast-validation.cc
@@ -98,6 +98,11 @@ ASTValidation::visit (AST::Function &function)
   std::set<Context> valid_context
     = {Context::INHERENT_IMPL, Context::TRAIT_IMPL};
 
+  const auto &qualifiers = function.get_qualifiers ();
+  if (qualifiers.is_async () && qualifiers.is_const ())
+    rust_error_at (function.get_locus (),
+		   "functions cannot be both %<const%> and %<async%>");
+
   if (valid_context.find (context.back ()) == valid_context.end ()
       && function.has_self_param ())
     rust_error_at (
-- 
2.42.1



More information about the Gcc-rust mailing list