Skip to content

Ability to skip files or blocks entirely #10220

Closed
@danielparks

Description

@danielparks

Description

Some experimental code of mine generates a 48,000+ line function1 that takes 20+ minutes to process with Clippy with all lints allowed.

It would be really helpful to be able to skip or ignore files or blocks of code entirely.

This seems like a fairly niche use-case, so perhaps this isn’t worth pursuing.

Discarded idea: using a feature

I considered adding a clippy feature, but this is a bit inconvenient. I usually run cargo clippy --all-features so hiding the code if feature = "clippy" works well, but I also run cargo test --all-features so I need to change one or the other. This is additionally complicated by needing to configure CI correctly.

These are not insurmountable problems at all, but they do make it harder, especially for new people who want to contribute to my project.

Proposal: setting --cfg clippy when Clippy runs

Code that you don’t want Clippy to look at could be guarded with #[cfg(not(clippy))].

I haven’t dug into the Clippy code yet, but this seems like it might be relatively easy to implement (I’m happy to volunteer).

I’m not sure if Clippy would need an option to disable the configuration option so that you can force it to look at all code. For my usage, I would be happy to just remove the #[cfg(not(clippy))] line and run clippy again, but I could imagine that some people would want to run Clippy on some code only some times.

I suppose another solution would be for cargo clippy to accept --cfg options.

Version

rustc 1.66.1 (90743e729 2023-01-10)
binary: rustc
commit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6
commit-date: 2023-01-10
host: x86_64-apple-darwin
release: 1.66.1
LLVM version: 15.0.2

Additional Labels

@rustbot label +C-enhancement

Footnotes

  1. The code is actually used in a private branch on another crate, but there is an example that generates the function. This is all a bit horrific, and I’m still considering just shelving the idea, but it’s much faster than anything else I’ve tried.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions