Skip to content

blacklisted_name should not be triggered in tests #8986

Open
@tamaroning

Description

@tamaroning

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 #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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't havegood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions