Skip to content

Commit

Permalink
Add trait context to ContextualASTVisitor
Browse files Browse the repository at this point in the history
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.patry@embecosm.com>
  • Loading branch information
P-E-P committed Nov 9, 2023
1 parent 854ee31 commit 92f8715
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gcc/rust/ast/rust-ast-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions gcc/rust/ast/rust-ast-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ class ContextualASTVisitor : public DefaultASTVisitor
FUNCTION,
INHERENT_IMPL,
TRAIT_IMPL,
TRAIT,
MODULE,
CRATE,
};
Expand All @@ -455,6 +456,8 @@ class ContextualASTVisitor : public DefaultASTVisitor

virtual void visit (AST::TraitImpl &impl) override;

virtual void visit (AST::Trait &trait) override;

template <typename T> void visit (T &item)
{
DefaultASTVisitor::visit (item);
Expand Down

0 comments on commit 92f8715

Please sign in to comment.