]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: expand: Add handling for macro expansion in pattern context
authorArthur Cohen <arthur.cohen@embecosm.com>
Wed, 13 Aug 2025 09:39:58 +0000 (11:39 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:38 +0000 (20:58 +0100)
commit56b11629cbe2e8b45c8fa408d3f58c0f5c0f8459
treea5ed8a034cf12582579f3ab669632e2848d6eb21
parentee8d54dc847e34ee88187caedbce6650d629436f
gccrs: expand: Add handling for macro expansion in pattern context

gcc/rust/ChangeLog:

* ast/rust-ast-fragment.cc (Fragment::is_pattern_fragment): New function.
(Fragment::take_pattern_fragment): Likewise.
(Fragment::assert_single_fragment): Likewise.
* ast/rust-ast-fragment.h: Declare them.
* ast/rust-ast.cc (SingleASTNode::SingleASTNode): Add new constructor for pattern
single AST nodes.
(SingleASTNode::operator=): Handle patterns.
(SingleASTNode::accept_vis): Likewise.
(SingleASTNode::is_error): Likewise.
(SingleASTNode::as_string): Likewise.
* ast/rust-ast.h: Add get_pattern_ptr() functions.
* ast/rust-expr.h: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-pattern.h: Likewise.
* ast/rust-stmt.h: Likewise.
* expand/rust-expand-visitor.cc (derive_item): Use new API enum values.
(expand_item_attribute): Likewise.
(expand_stmt_attribute): Likewise.
(ExpandVisitor::maybe_expand_pattern): New function.
(ExpandVisitor::expand_closure_params): Handle patterns.
(ExpandVisitor::visit): Add new visitors for patterns and missed exprs.
* expand/rust-expand-visitor.h: Declare them.
* expand/rust-macro-expand.cc (transcribe_pattern): New function.
(transcribe_context): Call it.
* expand/rust-macro-expand.h (struct MacroExpander): New Context type.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3726.rs: New test.
* rust/compile/issue-3898.rs: New test.
14 files changed:
gcc/rust/ast/rust-ast-fragment.cc
gcc/rust/ast/rust-ast-fragment.h
gcc/rust/ast/rust-ast.cc
gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-expr.h
gcc/rust/ast/rust-item.h
gcc/rust/ast/rust-pattern.h
gcc/rust/ast/rust-stmt.h
gcc/rust/expand/rust-expand-visitor.cc
gcc/rust/expand/rust-expand-visitor.h
gcc/rust/expand/rust-macro-expand.cc
gcc/rust/expand/rust-macro-expand.h
gcc/testsuite/rust/compile/issue-3726.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/issue-3898.rs [new file with mode: 0644]