https://gcc.gnu.org/g:87a1800acaecc0df515548fb16596f1ad19cd94f
commit 87a1800acaecc0df515548fb16596f1ad19cd94f Author: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com> Date: Thu Nov 9 19:45:08 2023 +0100 Add trait context to ContextualASTVisitor Some construct are forbidden in trait context (eg. pub, async...) and we'll need to reject those. To do so we need to identify a trait context. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Push the new trait context when visiting a trait. * ast/rust-ast-visitor.h: Add visit function prototype and TRAIT context. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com> Diff: --- gcc/rust/ast/rust-ast-visitor.cc | 8 ++++++++ gcc/rust/ast/rust-ast-visitor.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc index b9ff2f972803..b4d1011a03ea 100644 --- a/gcc/rust/ast/rust-ast-visitor.cc +++ b/gcc/rust/ast/rust-ast-visitor.cc @@ -1462,5 +1462,13 @@ ContextualASTVisitor::visit (AST::TraitImpl &impl) pop_context (); } +void +ContextualASTVisitor::visit (AST::Trait &trait) +{ + push_context (Context::TRAIT); + DefaultASTVisitor::visit (trait); + pop_context (); +} + } // namespace AST } // namespace Rust diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h index 98eab19ad3cf..48b3de57e3ac 100644 --- a/gcc/rust/ast/rust-ast-visitor.h +++ b/gcc/rust/ast/rust-ast-visitor.h @@ -442,6 +442,7 @@ protected: FUNCTION, INHERENT_IMPL, TRAIT_IMPL, + TRAIT, MODULE, CRATE, }; @@ -453,6 +454,8 @@ protected: virtual void visit (AST::TraitImpl &impl) override; + virtual void visit (AST::Trait &trait) override; + template <typename T> void visit (T &item) { DefaultASTVisitor::visit (item);