-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Verify that the AST does not have DUMMY_SP #35148
Comments
I think that if a syntax extension generates code with DUMMY_SP, we should use the span of its caller instead. |
While this is a good idea, it seems a better idea is to have the expander walk the plugin's output and respan anything with a
To elaborate on the third, when contexts go away, the user is not guaranteed to even receive anything with a span on it (in the case that the macro's input is empty). To fix this, either the macro will need to take a span to use, take the whole invocation form as input (okay, but still, a macro writer have to get and thread spans around), or need some other way to get to these spans (TLS, I guess). If the expander takes care of this, however, none of this will ever become a concern. |
As far as I know nothing has been done related to this. @nrc @jseyfried This seems relevant to the macros 2.0 work, perhaps that will solve or help some of this? |
I'm not sure if this is still relevant - can proc macros still generate code with DUMMY_SP? How could I test it? |
It would be interesting to insert a check to AST -> HIR lowering to figure out what sources are dummy spans coming from in practice. I think at least one legitimate source of dummy spans right now is prelude injection (and maybe proc macro harness and test harness injection). If #84373 is merged, then we'll have a single point to place such check in - |
ast_lowering: Introduce `lower_span` for catching all spans entering HIR This PR cherry-picks the `fn lower_span` change from rust-lang#84373. I also introduced `fn lower_ident` for lowering spans in identifiers, and audited places where HIR structures with spans or identifiers are constructed and added a few missing `lower_span`s/`lower_ident`s. Having a hook for spans entering HIR can be useful for things other than rust-lang#84373, e.g. rust-lang#35148. I also want to check whether this change causes perf regressions due to some accidental inlining issues. r? `@cjgillot`
Currently, syntax extensions can generate code with
DUMMY_SP
in its AST. All compiler diagnostics from that code, and all stack backtraces generated by that code, are basically worthless.That should not be possible. The lowered HIR should not have any DUMMY_SP.
cc @rust-lang/compiler
The text was updated successfully, but these errors were encountered: