Repository navigation
Add macro checks to lints #48855
Description
From #48385
Many of our lints trigger even when the code is within a macro defined by an external crate. They should include macro checks.
Clippy has a function for this already.
We should include this in librustc::lint somewhere, and use it for various lints. It should not be used for future compat lints.
One possible thing to do here is to work it into the lint framework itself, so that non-future-compat lints which are triggered on macro spans will not actually be emitted.
We should still have the helper function since some lints may involve multiple important spans so they need the ability to check them all.
Ideally there would be a way to turn this off, though -- in case you want to find issues in your macros. It's a tricky problem.
Willing to mentor the basic issue of importing the macro checks and applying them in most lints (or working it into the framework).
Activity
Manishearth commentedon Mar 8, 2018
@Dylan-DPC would you like to work on this?
oli-obk commentedon Mar 9, 2018
I'm not sure, but @flip1995 might be already on it (see #48364)
Manishearth commentedon Mar 9, 2018
So that's focusing on span_suggestion -- we need to both fix that and fix the general lint case, except for future compat lints
oli-obk commentedon Mar 9, 2018
In clippy we are doing this on a case-by-case basis. Do we really want to blanket ignore all lints in local expansions of external macros?
Manishearth commentedon Mar 9, 2018
Honestly I don't know. Future compat lints must show, but aside from that the cases where we want to still show a lint on a macro expansion is when the linted code is completely within the invocation, which can't be detected easily right now.
Dylan-DPC-zz commentedon Mar 9, 2018
@Manishearth Ye sure 👍
Manishearth commentedon Apr 5, 2018
Any updates?
Dylan-DPC-zz commentedon Apr 6, 2018
@Manishearth haven't started with it. Will work on it this weekend.
Dylan-DPC-zz commentedon Apr 6, 2018
@Manishearth is there a common place where all lints are used? or i have to hunt down each lint implementation?
Manishearth commentedon Apr 6, 2018
they all implement
EarlyLintPassorLateLintPass. The implementations are scattered.What you want to do is tweak
span_lintand similar functions to do the macro check, except for when the lint is a future compat lint (ignore this part for now)nrc commentedon Jul 2, 2018
From @cramertj on Discord: problematic interaction with
#[derive(fail)]alexcrichton commentedon Jul 17, 2018
I've revived #49755 at #52467, and I've confirmed @nrc that the warning with
derive(Fail)no longer happens after that PRAuto merge of #52467 - alexcrichton:lints-and-macros, r=Manishearth