rust-lang/rust-clippy

blacklisted_name should not be triggered in tests

Open

#8,986 opened on Jun 11, 2022

View on GitHub
 (5 comments) (0 reactions) (1 assignee)Rust (10,406 stars) (1,391 forks)batch import
C-bugI-false-positivegood first issue

Description

Summary

blacklisted_name should toralate use of such name as foo. As far as I see the source code, it tries to allow foo in tests, but it doesn't.

Similar to https://github.com/rust-lang/rust-clippy/issues/8758

Lint Name

blacklisted_name

Reproducer

I tried this code:

#![warn(clippy::blacklisted_name)]
fn main() {}

#[cfg(test)]
mod abc {
    fn _abc() {
        let foo = ();
        dbg!(foo);
    }
}

#[test]
fn bcd() {
    let foo = ();
    dbg!(foo);
}

fn _test() {
    let foo = ();
    dbg!(foo);
}

I saw this happen:

warning: use of a blacklisted/placeholder name `foo`
  --> src\main.rs:19:9
   |
19 |     let foo = ();
   |         ^^^
   |
note: the lint level is defined here
  --> src\main.rs:1:9
   |
1  | #![warn(clippy::blacklisted_name)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name

warning: use of a blacklisted/placeholder name `foo`
 --> src\main.rs:7:13
  |
7 |         let foo = ();
  |             ^^^
  |
note: the lint level is defined here
 --> src\main.rs:1:9
  |
1 | #![warn(clippy::blacklisted_name)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name

warning: use of a blacklisted/placeholder name `foo`
  --> src\main.rs:14:9
   |
14 |     let foo = ();
   |         ^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name

warning: use of a blacklisted/placeholder name `foo`
  --> src\main.rs:19:9
   |
19 |     let foo = ();
   |         ^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name

I expected to see this happen: No warning

Version

rustc 1.61.0-nightly (458262b13 2022-03-09)
binary: rustc
commit-hash: 458262b1315e0de7be940fe95e111bb045e4a2a4
commit-date: 2022-03-09
host: x86_64-pc-windows-msvc
release: 1.61.0-nightly
LLVM version: 14.0.0

Additional Labels

@rustbot label +E-easy

Contributor guide