Add a new check in AST validation pass that checks that no function
declaration in traits are declared const.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
const check.
* checks/errors/rust-ast-validation.h: Add visit function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
AST::ContextualASTVisitor::visit (function);
}
+void
+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");
+}
+
void
ASTValidation::visit (AST::Trait &trait)
{
virtual void visit (AST::Union &item);
virtual void visit (AST::Function &function);
virtual void visit (AST::Trait &trait);
+ virtual void visit (AST::TraitFunctionDecl &decl);
};
} // namespace Rust