Skip to content

Conditional compilation for configuration file? #11433

@ojeda

Description

@ojeda

Some lints that are configured via clippy.toml may need to react to conditional compilation.

For instance, for disallowed_macros, a project may want to warn only about a particular macro in some configurations (e.g. CI vs. development).

It could also be useful if Clippy were to identify unexpected paths to prevent mistakes (#11432), since it would allow the user to e.g. remove a given macro from the list if the macro is compiled out.

A workaround could be users generating Clippy's config file on the fly.

Perhaps Clippy could instead allow to be configured within the Rust source code (step-by-step), so that the #[cfg] syntax/machinery is reused, but I imagine there is a reason it was not done there (e.g. workspaces sharing config easily?), e.g.

// `m1` always disallowed.
#[clippy_config(disallowed_macros, "m1")]

// `m2` only disallowed if `X`.
#[cfg(X)]
#[clippy_config(disallowed_macros, "m2")]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions