Clippy not reporting errors until compiled targets are removed

The current (December 2020) version of Clippy doesn’t always report errors if another compile (cargo check, cargo build, etc) was run before running clippy itself.

Issues about this:

Workarounds listed in the issues are to clear the build files under target/ or to run: cargo +nightly clippy -Zunstable-options

As of at least February 2021 the issue remains, but I have found that merely touching all source files (touch **/*.rs) is sufficient to work around the problem.

I have since structured my .pre-commit.yaml files with the following to encode this:

  - repo: local
    hooks:
      - id: touch
        name: touch rust files (clippy workaround)
        entry: /bin/sh -c 'find . -name "*.rs" -print0 | xargs --null touch'
        language: script
        files: ^.+\.rs$
  - repo: https://github.com/doublify/pre-commit-rust
    rev: eeee35a89e69d5772bdee97db1a6a898467b686e # frozen: v1.0
    hooks:
      # Make sure clippy comes first and is located just after the touch hook above.
      # See also https://notes.nick.groenen.me/notes/clippy-issue-about-not-reporting-errors-until-compiled-targets-are-removed/
      - id: clippy
        args: ["--", "-D", "warnings"]
      - id: fmt
      - id: cargo-check