Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
felix-pb opened this issue Dec 21, 2020 · 7 comments
Labels
C-bug Category: bug

Comments

@felix-pb
Copy link

felix-pb commented Dec 21, 2020

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 (65cbdd2 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.

@felix-pb felix-pb added the C-bug Category: bug label Dec 21, 2020
@felix-pb felix-pb changed the title cargo clippy and cargo check doesn't seem to recognize source code changes without --release flag cargo clippy and cargo check doesn't recognize source code changes without --release flag Dec 21, 2020
@felix-pb felix-pb changed the title cargo clippy and cargo check doesn't recognize source code changes without --release flag cargo clippy and cargo check don't recognize source code changes without --release flag Dec 21, 2020
@felix-pb
Copy link
Author

felix-pb commented Dec 21, 2020

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.

@taiki-e
Copy link
Member

taiki-e commented Dec 21, 2020

I believe this is rust-lang/rust-clippy#4612

@Eh2406
Copy link
Contributor

Eh2406 commented Dec 21, 2020

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

@felix-pb
Copy link
Author

felix-pb commented Dec 21, 2020

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.

@taiki-e
Copy link
Member

taiki-e commented Dec 21, 2020

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.

@felix-pb
Copy link
Author

felix-pb commented Dec 21, 2020

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!

@ehuss
Copy link
Contributor

ehuss commented Dec 21, 2020

Closing as a duplicate of rust-lang/rust-clippy#4612.

@ehuss ehuss closed this as completed Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants