diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 477e889c5129..7555abc449cc 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -116,6 +116,16 @@ ASTValidation::visit (AST::Function &function) 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) { diff --git a/gcc/rust/checks/errors/rust-ast-validation.h b/gcc/rust/checks/errors/rust-ast-validation.h index 1052168ea728..f1c3018d142d 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.h +++ b/gcc/rust/checks/errors/rust-ast-validation.h @@ -41,6 +41,7 @@ class ASTValidation : public AST::ContextualASTVisitor 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