rust-lang / rust-lang/rust-clippy
`items_after_test_module` lints on `#[cfg(test)]` modules that don't have tests in them
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
This might be niche, but I have a crate that implements proptest::Arbitrary only when cfg(test). It does so in an inline module, but that inline module is not actually a test module - it's just cfg'd on test. Maybe it could only trigger if there are #[test] items inside? Though maybe expanding macros that might be test functions would conflict with detecting cfg(test). (also, separate, but it seems to be sorta spurious - this triggers it, but this doesn't)
Lint Name
items_after_test_module
Reproducer
I tried this code (sorry, pseudocode cause I'm not sure what causes it and what doesn't - occurs in the code in the link above in rust 1.76):
#[cfg_attr(test, derive(Arbitrary))]
struct Foo {
#[cfg_attr(test, proptest(strategy = "arbitrary::fancy_strategy()"))]
foo: u32,
}
#[cfg(test)]
mod arbitrary {
use super::*;
pub(super) fn fancy_strategy() -> impl Strategy<Value = u32> {
...
}
}
// more items...
I saw this happen:
items_after_test_module
I expected to see this happen:
nothing
Version
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
Additional Labels
No response
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 implementation and tests for the items_after_test_module lint, then reproduce the report with the supplied #[cfg(test)] module containing only a helper function. Compare it with the linked SpacetimeDB examples and verify that modules without test items no longer trigger the lint while genuine test modules still do.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100