fixed the duplicate metavariables issue#4444
Open
hriztam wants to merge 8 commits intoRust-GCC:masterfrom
Open
fixed the duplicate metavariables issue#4444hriztam wants to merge 8 commits intoRust-GCC:masterfrom
hriztam wants to merge 8 commits intoRust-GCC:masterfrom
Conversation
Addresses Rust-GCC#4409. Validate duplicate matcher bindings for `macro_rules!` during definition resolution so duplicates are diagnosed even if the macro is never invoked. gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Always emit the failed-to-match error when no rule matches. (MacroExpander::match_matcher): Remove duplicate-binding checks. * expand/rust-macro-expand.h (MacroExpander): Remove had_duplicate_error state. * resolve/rust-early-name-resolver-2.0.cc (check_matcher_for_duplicate_bindings): New helper. (Early::visit): Check for duplicate matcher bindings in macro definitions. gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/macro-duplicate-binding.rs: Check duplicate matcher bindings on an unused macro definition.
P-E-P
requested changes
Feb 23, 2026
Member
P-E-P
left a comment
There was a problem hiding this comment.
Some files are artifacts generated from the configure script and should not be pushed.
Contributor
Author
|
ok let me update the PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #4409.
This change moves duplicate matcher binding validation for
macro_rules!from invocation-time matching into macro-definition validation during early name resolution. This makes duplicate metavariable bindings fail even when the macro is never invoked, matching rustc’s behavior forduplicate matcher binding.It also adds an unused macro-definition warning pass in expansion by scanning AST macro definitions and checking whether each definition is referenced by a resolved invocation (excluding builtins and
#[macro_export]cases), producingunused macro definition.The expander-side duplicate-binding guard logic was removed since diagnostics are now emitted at definition validation time.
Tests:
gcc/testsuite/rust/compile/macros/mbe/macro-duplicate-binding.rsto cover the uninvoked reproducer and assert both:duplicate matcher bindingerrorunused macro definitionwarningAlso I tried to format the code using clang-format but that resulted in a much larger pr with a lot of files formatted at once, so I reverted it for the time being. Let me know if that is something which is needed
Signed-off-by: Hritam Shrivastava hritamstark05@gmail.com