Stream: t-compiler

Topic: How to detect whether a specific lint is `allow`ed?


Charles Lew (Apr 30 2020 at 05:25, on Zulip):

Hello, there's some compute-heavy calculation within one of the lints, which i am working on, and i want to skip the calculation if the lint is allow-ed. I wonder what's the proper way to do this detection? Thanks!

oli (Apr 30 2020 at 12:27, on Zulip):

Clippy has a helper for it: https://github.com/rust-lang/rust-clippy/blob/9a3b0a05888f7ad002b67bbe61739695967ce929/clippy_lints/src/utils/mod.rs#L1069

oli (Apr 30 2020 at 12:28, on Zulip):

I think you can just copy it to your code, as that one liner is probably not useful to be copied to rustc

Charles Lew (Apr 30 2020 at 13:21, on Zulip):

Thanks! I'm working with an early ctx lint though, but it's similar. i think i've worked my way out. I just need to extract a method within https://github.com/rust-lang/rust/blob/master/src/librustc_lint/levels.rs .

RalfJ (Apr 30 2020 at 21:38, on Zulip):

don't lints automatically get that?

RalfJ (Apr 30 2020 at 21:39, on Zulip):

like, I thought the entire point of declare_lint_pass! was to only run the pass if the lint is enabled

simulacrum (Apr 30 2020 at 21:41, on Zulip):

no, we always run all lint passes, the association with the lints they emit isn't actually used at all

simulacrum (Apr 30 2020 at 21:41, on Zulip):

well, it's how those lints get registered

simulacrum (Apr 30 2020 at 21:41, on Zulip):

but we could just as easily have them separate

simulacrum (Apr 30 2020 at 21:42, on Zulip):

and you can totally emit other lint passes' lints from your lint pass

RalfJ (May 02 2020 at 13:34, on Zulip):

oh

simulacrum (May 02 2020 at 15:01, on Zulip):

to be clear, I think this is probably a "bug" at some level, we should perhaps fix it

simulacrum (May 02 2020 at 15:02, on Zulip):

rustc actually merges all lint passes IIRC into one for performance reasons

Last update: Jun 04 2020 at 18:40UTC