Fix asm sym operand parsing for parenthesized expr fragments#21588
Conversation
|
Please note that we require disclosure of AI usage, if you used them. |
|
I'm not sure if it is good to overly relax the syntax to accept any |
|
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. |
|
Hi @oxalica — thanks for the earlier feedback! I revised the approach to avoid relaxing
Could you please take another look at the transcriber heuristic and the test coverage? |
|
No no no. If we're accepting that we should patch something until we fix macros properly (which I'm not sure is a good idea but maybe it is), it is definitely not a good idea to do that in macro_rules general handling. Change the parser to accept parentheses inside rust-analyzer/crates/parser/src/grammar/expressions/atom.rs Lines 409 to 413 in 4eac290 |
7eef93d to
6322c04
Compare
|
Squashed! |
Fixes #21582
Summary
When capturing a path via
$e:expr, macro expansion treats it asFragment::Exprand wraps it in parentheses to preserve operator precedence.This results in
sym (generic::<i32>), but the existing parser expected a path immediately aftersymand failed when seeing(, leading to a parse failure and a bogus typed-hole diagnostic.Changes
symas an expressionWhy this approach
This keeps parsing more permissive while keeping the semantic requirement (“
symexpects a path”) enforced during lowering.Testing
symoperand causes parsing errors #21582cargo test(and any focused test targets you ran)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.