Closed
Description
Summary
cargo clippy --tests -- -D clippy::dbg-macro
complains about use of dbg!
in modules marked #[cfg(test)]
.
(In #8481 I reported this false positive for test functions themselves and that was fixed in #8500, but the problem remains in non-test-entrypoint functions in test modules.)
Lint Name
dbg-macro
Reproducer
I tried this code:
fn main() {
}
#[cfg(test)]
mod test {
fn wombat() {
dbg!("wombat");
}
#[test]
fn t() {
wombat();
}
}
and ran cargo clippy --locked --offline --tests -- -D clippy::dbg-macro
.
I saw this happen:
Checking foo v0.1.0 (/volatile/rustcargo/Rustup/Arti/experiments)
error: `dbg!` macro is intended as a debugging tool
--> src/main.rs:7:9
|
7 | dbg!("wombat");
| ^^^^^^^^^^^^^^
|
= note: requested on the command line with `-D clippy::dbg-macro`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro
help: ensure to avoid having uses of it in version control
|
7 | "wombat";
| ~~~~~~~~
error: could not compile `foo` due to previous error
I expected to see this happen: the code should be accepted without complaint.
IMO --tests
ought to mean just "check my tests too, but treating them as tests", not "apply to my tests the rules for non-test code".
Version
rustc 1.61.0-nightly (1bfe40d11 2022-03-18)
binary: rustc
commit-hash: 1bfe40d11c3630254504fb73eeccfca28d50df52
commit-date: 2022-03-18
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0
Additional Labels
No response