Skip to content

fix(semantic): match a pattern subtree only against a call subtree with the same delimiters - #10303

Open
orizi wants to merge 1 commit into
graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr2-duplicate-placeholder-f3from
graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr3-subtree-delimiters-f5
Open

fix(semantic): match a pattern subtree only against a call subtree with the same delimiters#10303
orizi wants to merge 1 commit into
graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr2-duplicate-placeholder-f3from
graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr3-subtree-delimiters-f5

Conversation

@orizi

@orizi orizi commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

The MacroElement::Subtree matching arm never compared the delimiter kind of the pattern subtree
against the input subtree, so a rule ([$x:ident]) matched the call m!({a}). Compare the
delimiter kinds, treating a mismatch as a rule-match failure so a later rule may still match, as
rustc does.

Also resolves the adjacent TODO(Dean) about bracket terminal consistency: a pattern subtree
cannot have inconsistent delimiters in the AST, and a pattern missing a closing delimiter is
reported by the parser and its rule is already dropped - so no declaration time check is needed.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr3-subtree-delimiters-f5 branch 2 times, most recently from a53a9fc to e2eb1e2 Compare August 5, 2026 10:54
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr2-duplicate-placeholder-f3 branch from 08026fe to b654579 Compare August 5, 2026 10:54
@orizi
orizi marked this pull request as ready for review August 5, 2026 11:10
@cursor

cursor Bot commented Aug 5, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes core user-defined macro matching in the semantic layer; behavior shifts for calls that previously matched across delimiter kinds, but scope is localized and heavily tested.

Overview
User-defined inline macro rule matching now treats subtree delimiter kind ((), [], {}) as part of the pattern, aligned with rustc: a rule like ([$x:ident]) no longer matches macro!({a}).

In macro_declaration.rs, the MacroElement::Subtree arm pairs WrappedMacro / WrappedTokenTree variants before recursing; a mismatch fails the rule (not a user error) so later rules can still match. The TODO on verifying bracket terminals at declaration time is removed—the parser already rejects inconsistent delimiters and drops broken rules.

Tests cover multi-rule fallback, nested inner subtrees, non-first subtree elements, empty {} vs [], and E2158 when no rule fits.

Reviewed by Cursor Bugbot for commit e6ca70b. Bugbot is set up for automated code reviews on this repo. Configure here.

@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr2-duplicate-placeholder-f3 branch from b654579 to e8f1e18 Compare August 5, 2026 11:59
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr3-subtree-delimiters-f5 branch 2 times, most recently from 09a334a to 9719407 Compare August 5, 2026 15:15
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr2-duplicate-placeholder-f3 branch from e8f1e18 to 7a54e5b Compare August 5, 2026 15:15
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr2-duplicate-placeholder-f3 branch from 7a54e5b to 5596948 Compare August 5, 2026 16:58
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr3-subtree-delimiters-f5 branch from 9719407 to 1807ca6 Compare August 5, 2026 16:58
…th the same delimiters

The `MacroElement::Subtree` matching arm never compared the delimiter kind of the pattern subtree
against the input subtree, so a rule `([$x:ident])` matched the call `m!({a})`. Compare the
delimiter kinds, treating a mismatch as a rule-match failure so a later rule may still match, as
rustc does.

Also resolves the adjacent `TODO(Dean)` about bracket terminal consistency: a pattern subtree
cannot have inconsistent delimiters in the AST, and a pattern missing a closing delimiter is
reported by the parser and its rule is already dropped - so no declaration time check is needed.
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/matcher-correctness.pr3-subtree-delimiters-f5 branch from 1807ca6 to e6ca70b Compare August 6, 2026 11:33
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.

2 participants