From 92f8715848052872acebc6f64df26a89d675249d Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Thu, 9 Nov 2023 19:45:08 +0100 Subject: [PATCH] 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 --- 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 42df2eceb665..5c7cc705c5d0 100644 --- a/gcc/rust/ast/rust-ast-visitor.cc +++ b/gcc/rust/ast/rust-ast-visitor.cc @@ -1473,5 +1473,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 94029479a385..44ebec747d40 100644 --- a/gcc/rust/ast/rust-ast-visitor.h +++ b/gcc/rust/ast/rust-ast-visitor.h @@ -444,6 +444,7 @@ class ContextualASTVisitor : public DefaultASTVisitor FUNCTION, INHERENT_IMPL, TRAIT_IMPL, + TRAIT, MODULE, CRATE, }; @@ -455,6 +456,8 @@ class ContextualASTVisitor : public DefaultASTVisitor virtual void visit (AST::TraitImpl &impl) override; + virtual void visit (AST::Trait &trait) override; + template void visit (T &item) { DefaultASTVisitor::visit (item);