-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incomplete syntax handling for proc-macros produces invalid TokenStream
with {
/}
chars as a Punct
rather than a Group
#18244
Comments
{
as a Punct
rather than a Group
TokenStream
with {
/}
chars as a Punct
rather than a Group
This probably comes from parser recovery. We need to either make it affect macro tt well, or better, not insert non-existing tokens. |
It's not parser recovery; it's this: rust-analyzer/crates/hir-expand/src/fixup.rs Lines 151 to 161 in 5982d9c
(Original code by me, FIXME added by @Veykril and he's of course correct ;) ) |
Some more context. While digging a bit more I also uncovered a bug in The standard library's The problem is worsened by the bug in |
@rustbot release-assignment This turned out way more nightmare-y than I thought and I have other things to do. If anybody is interested in taking my work, my almost complete branch is on GitHub: https://github.com/ChayimFriedman2/rust-analyzer/tree/punct-brace. It passes all tests, but has a bug as the commit message explains. A simple fix may be to never omit a delimiter (and thus make bugs like this still possible, just more rare). |
rust-analyzer version:
rust-analyzer version: 0.3.2129-standalon
rustc version:
rustc 1.81.0 (eeb90cda1 2024-09-04)
editor or extension: VSCode v0.3.2129
I've stumbled on a bug when using my proc-macro
#[bon::builder]
.The minimal reproduction of this is:
where
my_lovely_macro
is defined as thisIf you take a look at the panic message from RA hints
it looks like this:
Notice how there are two
Punct
items for{
and}
braces in this list? This is an invalid token tree.syn
fails to parse this syntax, because curly braces are never meant to bePunct
characters, they must always be balanced and they are only expected as part of aGroup
token tree.This produced a panic in my
bon::builder
macro visible to the user writing the code if they have an incompleteif
somewhere while writing the function body (the entire function is underlined in red and no IDE hints are provided). I'll fix that panic inbon
separately to make my macro more bug-resilient to situations like this, but RA should also fix this.The text was updated successfully, but these errors were encountered: