cargo clippy and cargo check don't recognize source code changes without --release flag

Created on 21 Dec 2020  路  7Comments  路  Source: rust-lang/cargo

Problem
cargo clippy and cargo check don't recognize source code changes unless they are run with the --release flag (see steps below). I expect that both commands should output the same thing (e.g. same lints for cargo clippy) with or without the --release flag when the source code changes.

Steps

  1. Run cargo new playground and cd into the project root.
  2. Run cargo clippy and the output is:
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
  1. Run cargo clippy --release and the output is:
Checking playground v0.1.0 (/Users/felix-pb/Desktop/playground)
Finished release [optimized] target(s) in 0.04s
  1. Add () on a new line after the print statement in src/main.rs.
  2. Run cargo clippy and the output is:
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
  1. Run cargo clippy --release and the output is:
Checking playground v0.1.0 (/Users/felix-pb/Desktop/playground)
warning: unneeded unit expression
 --> src/main.rs:3:5
  |
3 |     ()
  |     ^^ help: remove the final `()`
  |
  = note: `#[warn(clippy::unused_unit)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

warning: 1 warning emitted

Notes

Output of cargo version: cargo 1.48.0 (65cbdd2dc 2020-10-14)

I'm using the current latest stable version of rustc.
Output of rustc --version: rustc 1.48.0 (7eac88abb 2020-11-16)
The problem is happening on both my personal and work laptops, both of which are macOS. My personal laptop is running macOS Big Sur (version 11.1) and my work laptop is running macOS Catalina (version 10.15.7). As far as I know, I haven't modified the default cargo settings on either of my laptops.

C-bug

Most helpful comment

the issue happens even if I never run cargo check nor cargo build nor cargo run on the project. Perhaps there is an implicit cargo check when I run cargo clippy though?

I guess this is due to rust-analyzer (or rls) automatically run cargo check.

All 7 comments

I just realized that the issue happens when I run the commands inside the VS Code terminal, but not when I run the commands inside the macOS built-in "Terminal" app. Although I'm not sure, this looks like an issue with VS Code and not with Cargo. I'll investigate more later this week.

There are known bugs with clippy reusing caches from check, and so in effect clippy not being run. And @taiki-e found the link before me. It has been a long time cumming but Cargos part of the fix is coming in https://github.com/rust-lang/cargo/pull/8976

Alright, but just to be clear, the issue happens even if I never run cargo check nor cargo build nor cargo run on the project. Perhaps there is an implicit cargo check when I run cargo clippy though? Also, it doesn't explain why it works fine in the built-in macOS "Terminal" app, but not in the VS Code terminal.

the issue happens even if I never run cargo check nor cargo build nor cargo run on the project. Perhaps there is an implicit cargo check when I run cargo clippy though?

I guess this is due to rust-analyzer (or rls) automatically run cargo check.

Bingo! That explains both why the issue happens even if I don't run cargo check before cargo clippy, and why it only happens in VS Code and not in the built-in Terminal app. I confirmed this by performing step 4 (i.e. adding () after the print the statement) in VS Code, and then running cargo clippy in the Terminal app where I get the invalid output (contrary to when I was performing step 4 with nano). That makes sense with your guess because cargo check was run by rust-analyzer in VS Code, but obviously not by nano.

Thanks, can't wait for this fix!

Was this page helpful?
0 / 5 - 0 ratings