Skip to content

Add support for cfg field for disallowed_* lints #14760

@nik-rev

Description

@nik-rev

Description

Usecase: use pretty_assertions::assert_eq instead of std::assert_eq in cfg(test)
But allow using std::assert_eq in non-test code

You can hack this using #[cfg_attr(test, allow(clippy::disallowed_macros))], but this will affect other macros defined in disallowed_macros when you might only want to do this for a list of macros

Lints affected:

  • disallowed_macros
  • disallowed_methods
  • disallowed_types

Add support to specify cfg field for disallowed items

disallowed-macros = [
  { cfg = "test", path = "std::assert_ne", reason = "use `pretty_assertions::assert_ne` instead" },
  { cfg = "test", path = "std::assert_eq", reason = "use `pretty_assertions::assert_eq` instead" },
]

Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

Additional Labels

@rustbot label +C-enhancement

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