Clippy ignores crate wide warn/deny

Clippy is ignoring directives unless in the current file/module. E.g. using #![deny(clippy::print_stdout)] in lib.rs and then putting a println!() call in another module does not trigger the lint? Minimal reproducer 4 comments down in thread.

cargo --version
cargo 1.51.0-nightly (a73e5b7d5 2021-01-12)
clippy --version
clippy 0.1.51 (4253153 2021-01-17)

Any ideas please?

I can't reproduce this in a simple program. For example, running Clippy on this file produces an error:

#![deny(clippy::print_stdout)]
mod foo {
    fn bar() {
        println!("");
    }
}

Are you perhaps including the same file in multiple crates? For example, do you have lib.rs and main.rs that both say mod foo;? (If so, you should include this modilue only in your library crate, and use it in your binary crate via the library.)

Thanks for your response, I'll see if I can come up with a minimal repro.

main.rs

#![deny(clippy::print_stdout)]

mod foo;

#[allow(clippy::print_stdout)]
fn main() {
    println!("Hello, world!");
}

foo.rs

pub fn foo() {
    println!("This should trigger clippy");
}

clippy output

/home/tobin/.cargo/bin/cargo clippy --all-targets -Zunstable-options --manifest-path /home/tobin/tmp/clippy/Cargo.toml 
warning: function is never used: `foo`
 --> src/foo.rs:1:8
  |
1 | pub fn foo() {
  |        ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

warning: function is never used: `foo`
 --> src/foo.rs:1:8
  |
1 | pub fn foo() {
  |        ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.00s

Cargo-Process finished at Wed Jan 20 15:17:11

Here we see that clippy parses foo.rs but does not pick up the print statement.

Interesting. It looks like similar bugs in Clippy have been found and fixed in the past. This should probably be reported as a new issue.

1 Like

Ok, thought I was being brain dead. Will report it. Thanks for the help!

https://github.com/rust-lang/rust-clippy/issues/6610

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.