rust-lang / rust-lang/rust-clippy
Add support for `cfg` field for `disallowed_*` lints
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
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_macrosdisallowed_methodsdisallowed_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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the configuration handling, implementations, and tests for the disallowed_macros, disallowed_methods, and disallowed_types lints. Compare their existing disallowed-item entries with the proposed cfg field, then verify that cfg=test restricts each listed item as intended without affecting other configurations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100