Skip to content
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

How to avoid lints on generated code...? #487

Open
nikomatsakis opened this issue Apr 5, 2024 · 3 comments
Open

How to avoid lints on generated code...? #487

nikomatsakis opened this issue Apr 5, 2024 · 3 comments

Comments

@nikomatsakis
Copy link
Member

nikomatsakis commented Apr 5, 2024

#483 improved the spans for field getters and things to use the span of the field. This makes working with salsa much nicer in rust-analyzer, generates better errors, etc, but it also leads to annoying clippy warnings in the generated code. I'm not 100% sure what's going on but my theory is that the newer spans are not tagged as coming from a procedural macro (they have no expansion stack) so clippy is not ignoring them anymore. Is there a "best practice" here that I am ignoring?

For now I added "allow" declarations in #486, but it doesn't seem right.

@nikomatsakis
Copy link
Member Author

cc @xFrednet ?

@xFrednet
Copy link

xFrednet commented Apr 5, 2024

but my theory is that the newer spans are not tagged as coming from a procedural macro

This is most likely the case. Clippy uses the spans from rustc and usually just checks if they are from an expansion. Span::from_expansion()

The quite_with_span macro prevents the expansion information to be added to the span. This can produce nicer error messages, but makes it difficult for Clippy.

Since this seems to generate an impl ... block, you can try to add the #[automatically_derived] attribute to it. That should suppress some lints.

It would be good if rustc could somehow retain the information where tokens come from, even if the span is manipulated by a macro, but currently that's not the case. The question would also be the question if that's actually worth it performence and memory wise.

Currently, we recomment to add #[allow] attributes like you did and #[automatically_derived]. One simple improvement could be to have rustc add the #[automatically_derived] attribute autoatically. It doesn't seem to do that always.

@nikomatsakis
Copy link
Member Author

nikomatsakis commented Apr 6, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants