Skip to content

Detect unknown features inside #[cfg(feature = "…")] blocks #11649

@emilk

Description

@emilk

What it does

Look for #[cfg(feature = "NAME")], cfg!(feature = "NAME"), #[cfg_attr(feature = "NAME", …)] etc and check that NAME is a real feature found in Cargo.toml

Advantage

  • Catches typos (#[cfg(feature = "sedre")])
  • Catches refactors that removes or renames a feature

Example

#[cfg_attr(feature = "sedre", derive(serde::Deserialize, serde::Serialize))]
struct Foo {
}

Suggested output:

Clippy: "No feature called sedre. Available features are: default, serde

Related

May sounds similar, but are different:

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions