Skip to content

cargo clippy --fix seems to imply --tests which is at least undocumented #10690

@tsdh

Description

@tsdh

Summary

After reading the rust 1.69 release notes, I wanted to give cargo clippy --fix a try and thereby found out that while cargo clippy had nothing to complain about in my sample project, cargo clippy --fix issued several warnings (which couldn't be fixed automatically). Turns out, all warnings were in #[test] functions. And indeed, cargo clippy --tests issued the same warnings.

So it seems like --fix implies --tests. Not a big deal but at least not quite expected and especially not documented, AFAICT.

❯ cargo clippy --version
clippy 0.1.69 (84c898d 2023-04-16)

Reproducer

I tried this code:

fn main() {
    println!("Hello, world!");
}

#[test]
fn test() {
    let foo = "clippy will complain about placeholder name foo.";
    println!("{foo}");
}

I expected the first two clippy invocations but not the third:

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

❯ cargo clippy --tests
warning: use of a disallowed/placeholder name `foo`
 --> src/main.rs:7:9
  |
7 |     let foo = "clippy will complain about placeholder name foo.";
  |         ^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names
  = note: `#[warn(clippy::disallowed_names)]` on by default

warning: `clippy-bug` (bin "clippy-bug" test) generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s

❯ cargo clippy --fix --allow-dirty
    Checking clippy-bug v0.1.0 (/home/horn/tmp/clippy-bug)
warning: use of a disallowed/placeholder name `foo`
 --> src/main.rs:7:9
  |
7 |     let foo = "clippy will complain about placeholder name foo.";
  |         ^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names
  = note: `#[warn(clippy::disallowed_names)]` on by default

warning: `clippy-bug` (bin "clippy-bug" test) generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s

Version

rustc 1.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-unknown-linux-gnu
release: 1.69.0
LLVM version: 15.0.7

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions