rust-lang / rust-lang/rust-clippy

blacklisted_name should not be triggered in tests

Open
#8,986 5 comments 0 reactions 1 assignee View on GitHub

@yerke is already working on this.

Since Jul 17, 2022.

C-bug good first issue I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.