Skip to content

Handle patterns in macro expansion - #4076

Merged
CohenArthur merged 2 commits into
Rust-GCC:masterfrom
CohenArthur:macro-expand-patterns
Aug 14, 2025
Merged

Handle patterns in macro expansion#4076
CohenArthur merged 2 commits into
Rust-GCC:masterfrom
CohenArthur:macro-expand-patterns

Conversation

@CohenArthur

Copy link
Copy Markdown
Member

Fixes #3898
Fixes #3726

  • ast: Cleanup SingleASTNode::NodeType
  • expand: Add handling for macro expansion in pattern context

This should be reworked with a proper ExternalVisitor or ReseatVisitor or something.

@CohenArthur
CohenArthur force-pushed the macro-expand-patterns branch from cf88af9 to e8b326c Compare August 14, 2025 08:38
gcc/rust/ChangeLog:

	* ast/rust-ast.h: Change NodeType to enum class Kind.
	* ast/rust-ast-fragment.cc: Use new names.
	* ast/rust-ast-fragment.h: Likewise.
	* ast/rust-ast.cc (SingleASTNode::SingleASTNode): Likewise.
@CohenArthur
CohenArthur enabled auto-merge August 14, 2025 08:38
@CohenArthur
CohenArthur force-pushed the macro-expand-patterns branch from e8b326c to 5c38744 Compare August 14, 2025 09:25
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.
@CohenArthur
CohenArthur added this pull request to the merge queue Aug 14, 2025
Merged via the queue into Rust-GCC:master with commit 6709c31 Aug 14, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle run_utf8_validation(v: &[u8]) properly gccrs enters infinite loop/hangs when compiling match patterns with macros or tuple structs

2 participants