Skip to content

Conversation

@railgun-0402
Copy link

@railgun-0402 railgun-0402 commented Feb 4, 2026

Fixes #21582

Summary

When capturing a path via $e:expr, macro expansion treats it as Fragment::Expr and wraps it in parentheses to preserve operator precedence.
This results in sym (generic::<i32>), but the existing parser expected a path immediately after sym and failed when seeing (, leading to a parse failure and a bogus typed-hole diagnostic.

Changes

  • Parse the operand after sym as an expression
  • During lowering, extract a path from the expression (so parenthesized forms are handled correctly)

Why this approach

This keeps parsing more permissive while keeping the semantic requirement (“sym expects a path”) enforced during lowering.

Testing

AI Usage

AI disclosure:

I used ChatGPT to help draft the PR description and clarify the root-cause explanation.
The implementation and tests were written and validated by me.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 4, 2026
@ChayimFriedman2
Copy link
Contributor

Please note that we require disclosure of AI usage, if you used them.

@oxalica
Copy link
Contributor

oxalica commented Feb 4, 2026

I'm not sure if it is good to overly relax the syntax to accept any sym <expr>, which is not accepted by rustc currently. Note that rustc will reject it if you write sym (func) directly (see also syntax reference).

@railgun-0402
Copy link
Author

Good point — I agree we shouldn’t accept a broader sym syntax than rustc.

The problematic case here is $e:expr in macro expansion, where the operand can be wrapped in invisible delimiters for precedence, even though users didn’t write parentheses.

I’ll adjust the change to keep the syntax strict (path-only), and only handle the invisible-delimiter wrapping so that sym (func) written directly is still rejected, matching rustc. I’ll also add a regression test for sym (func) to ensure we stay compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invisible delimiters after asm sym operand causes parsing errors

4 participants