diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 0ba73c67415..b06b027f0a5 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -62,4 +62,23 @@ ASTValidation::visit (AST::ConstantItem &const_item) AST::ContextualASTVisitor::visit (const_item); } +void +ASTValidation::visit (AST::ExternalFunctionItem &item) +{ + auto ¶ms = item.get_function_params (); + + if (params.size () == 1) + rust_error_at ( + params[0].get_locus (), + "C-variadic function must be declared with at least one named argument"); + + for (auto it = params.begin (); it != params.end (); it++) + if (it->is_variadic () && it + 1 != params.end ()) + rust_error_at ( + it->get_locus (), + "%<...%> must be the last argument of a C-variadic function"); + + AST::ContextualASTVisitor::visit (item); +} + } // namespace Rust diff --git a/gcc/rust/checks/errors/rust-ast-validation.h b/gcc/rust/checks/errors/rust-ast-validation.h index a21bcc44f68..6028b21ff00 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.h +++ b/gcc/rust/checks/errors/rust-ast-validation.h @@ -36,6 +36,7 @@ class ASTValidation : public AST::ContextualASTVisitor virtual void visit (AST::ConstantItem &const_item); virtual void visit (AST::Lifetime &lifetime); virtual void visit (AST::LoopLabel &label); + virtual void visit (AST::ExternalFunctionItem &item); }; } // namespace Rust