Avoid panic when an item-scope inline macro lacks an arg-list bracket - #9961
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
PR SummaryLow Risk Overview Adds a regression test case in Reviewed by Cursor Bugbot for commit fd7802d. Bugbot is set up for automated code reviews on this repo. Configure here. |
5c574c7 to
873e65e
Compare
dd93a77 to
53d4ff2
Compare
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).
Item-scope invocations like `m!` (no `()` / `[]` / `{}`) construct an
`ItemInlineMacro` whose argument subtree is `WrappedTokenTree::Missing(_)`. The
parser already reports `E1006`; `is_macro_rule_match` then panicked on the
`unreachable!` arm of the bracket-shape dispatch.
Return `None` for the `Missing` arm so the rule simply fails to match and the
caller's `InlineMacroNoMatchingRule` path takes over. Function-scope invocations
already short-circuit before reaching this function, so they are unaffected.
Fixes #9938.
53d4ff2 to
fd7802d
Compare

Summary
Fixes an ICE (Internal Compiler Error) that occurred when a user-defined inline macro was invoked at item scope without argument brackets (e.g.,
m!with no following(...),[...], or{...}). TheMissingvariant ofWrappedTokenTreewas previously markedunreachable!(), causing a panic. It now returnsNonefromis_macro_rule_match, allowing the compiler to emit proper diagnostics instead of crashing.Type of change
Please check one:
Why is this change needed?
When a user-defined inline macro was invoked without an argument list at item scope, the
WrappedTokenTree::Missingvariant was hit insideis_macro_rule_match, which contained anunreachable!()assertion. This caused the compiler to panic (ICE) rather than report a diagnostic.What was the behavior or documentation before?
The compiler would ICE when encountering a macro invocation like
m!(missing argument brackets) at item scope.What is the behavior or documentation after?
The compiler now gracefully handles the missing argument list by returning
Nonefromis_macro_rule_match, resulting in proper diagnostics:E1006: Missing tokens — expected an argument list wrapped in parentheses, brackets, or braces.E1001: Missing token;.E2158: No matching rule found in inline macrom.Related issue or discussion (if any)
Regression fix for #9938.
Additional context
A test case covering this regression has been added to the inline macros test data.