Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EarlyLintPass::check_mac() is not called in non-toplevel modules #5721

Closed
rhysd opened this issue Jun 15, 2020 · 1 comment · Fixed by #8518
Closed

EarlyLintPass::check_mac() is not called in non-toplevel modules #5721

rhysd opened this issue Jun 15, 2020 · 1 comment · Fixed by #8518
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@rhysd
Copy link
Contributor

rhysd commented Jun 15, 2020

Environment

  • cargo clippy -V: clippy 0.0.212 (d4092ace 2020-05-11)
  • OS: macOS 10.14

Repro

  1. Run cargo new foo
  2. Put src/main.rs and src/nested.rs as follows
  3. Run cargo clippy
  • main.rs
#![warn(clippy::print_stdout)]
#![warn(clippy::dbg_macro)]

mod nested;

fn main() {
    dbg!("hi");
    println!("Hello, world!");
    nested::bye();
}
  • nested.rs
pub fn bye() {
    dbg!("bye");
    println!("bye bye");
}

Expected behavior

cargo clippy causes 4 warnings; 2 print_stdout warnings and 2 dbg_macro warnings, 2 caused in main.rs and 2 caused in nested.rs.

Actual behavior

cargo clippy causes 2 warnings; 1 print_stdout warning and 1 dbg_macro warning, 2 caused in main.rs. No warning is detected in nested.rs.

Output:

warning: `dbg!` macro is intended as a debugging tool
 --> src/main.rs:7:5
  |
7 |     dbg!("hi");
  |     ^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:2:9
  |
2 | #![warn(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 |     "hi";
  |     ^^^^

warning: use of `println!`
 --> src/main.rs:8:5
  |
8 |     println!("Hello, world!");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::print_stdout)]
  |         ^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#print_stdout

warning: 2 warnings emitted

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

Investigation

Both print_stdout and dbg_macro rules are using EarlyLintPass::check_mac method. It seems that check_mac is only called on toplevel module (lib.rs or main.rs).

@rhysd rhysd changed the title check_mac in EarlyLintPass does not work in non-toplevel modules EarlyLintPass::check_mac() is not called in non-toplevel modules Jun 15, 2020
@flip1995 flip1995 added the C-bug Category: Clippy is not doing the correct thing label Jun 15, 2020
@repi
Copy link

repi commented Mar 9, 2021

We were testing the print_stdout and print_stderr in our codebases and think ran into this issue also of the lint being ineffective due to not really running on most of our code. Our hope was to find stray println! somewhere deep down in our modules but wasn't caught

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants