-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Rustc passes syntactically invalid input to attribute macros #90256
Comments
This is probably due to parser recovery - in all of the affected versions, the parser was able to parse an Now, we no longer rely on pretty-printing when incoming macros. The original (syntactically invalid) tokenstream is passed to the macro, without any kind of modification. |
See #76360 (comment) for a previous discussion of this kind of issue. |
Thanks for the link! The behavior I would expect is for the attribute macro to be run on the prettyprinted recovered input, iow the invalid node is snipped out or otherwise fixed up prior to the macro expansion. I think this is described as option 1 in your post. I left a comment on the other issue to that effect. |
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. @rustbot label -I-prioritize +P-high |
This seems like a real problem. I'm asking @estebank and @compiler-errors to try to dedicate some brain cycles to looking over the suggestions here and trying to drive progress towards a solution. |
Discussed at 2023 Q1 P-high review Arguably this is folded in with #76360, which has already (also) been handed off to WG-diagnostics, specifically @estebank and @compiler-errors , for some dedicated brain cycle time. |
It used to be the case that attribute macros would only ever be invoked with syntactically valid input. Rustc would snip out or otherwise fix up invalid syntax prior to dispatching the macro invocation. This ensures that rustc's recovery from the invalid syntax, and any diagnostics emitted by rustc to that effect, are consistent with any subsequent diagnostics emitted by the macro, rather than requiring both to perform independent and inconsistent heuristics to recover from the invalid input.
However, it looks like recent rustc versions (1.51+) have begun invoking attribute macros on invalid syntax. Can we find out whether this behavior is intended or a regression from recent Span-related work (#43081 — @Aaron1011)? IMO the newfangled behavior is not necessarily desirable so I have filed this as a regression.
trait T {}
as input. Invalid syntax has been snipped out.trait T { fn run(); }
as input, invalid syntax snipped out with finer granularity.trait T { fn run(&); }
which is invalid syntax and not necessarily desirable.The text was updated successfully, but these errors were encountered: