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

A newly created clippy.toml does not trigger a rebuild #9928

Open
jimblandy opened this issue Nov 21, 2022 · 3 comments
Open

A newly created clippy.toml does not trigger a rebuild #9928

jimblandy opened this issue Nov 21, 2022 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@jimblandy
Copy link

Summary

If results from a previous run are present, Clippy ignores changes to a "clippy.toml" file. This makes debugging frustrating, because Clippy's outputs are not a function of its current ostensible inputs.

The following transcript shows that, even if clippy.toml has invalid contents, Clippy doesn't notice until cargo clean removes its cached results.

$ cargo clean
$ cargo clippy
    Checking play-clippy v0.1.0 (/home/jimb/rust/play-clippy)
warning: the `Err`-variant returned from this function is very large
 --> src/main.rs:3:13
  |
3 | fn foo() -> Result<(), Error> {
  |             ^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 4000 bytes
  |
  = note: `#[warn(clippy::result_large_err)]` on by default
  = help: try reducing the size of `Error`, for example by boxing large elements or replacing it with `Box<Error>`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err

warning: `play-clippy` (bin "play-clippy") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.13s
$ echo 'msrv = "slurve"' > clippy.toml
$ cargo clippy
warning: the `Err`-variant returned from this function is very large
 --> src/main.rs:3:13
  |
3 | fn foo() -> Result<(), Error> {
  |             ^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 4000 bytes
  |
  = note: `#[warn(clippy::result_large_err)]` on by default
  = help: try reducing the size of `Error`, for example by boxing large elements or replacing it with `Box<Error>`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err

warning: `play-clippy` (bin "play-clippy") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
$ cargo clean
$ cargo clippy
    Checking play-clippy v0.1.0 (/home/jimb/rust/play-clippy)
error: error reading Clippy's configuration file. `slurve` is not a valid Rust version

error: could not compile `play-clippy` due to previous error
$ 

Reproducer

I tried this code:

<code>

I expected to see this happen:

Instead, this happened:

Version

No response

Additional Labels

No response

@jimblandy jimblandy added the C-bug Category: Clippy is not doing the correct thing label Nov 21, 2022
@Alexendoo
Copy link
Member

The situation should be a bit better with #9707, after that changes to existing config files will trigger a rebuild. That'll arrive in the next nightly after rust-lang/rust#104688 is merged

It doesn't fix your example though if clippy.toml is newly created, I can't think of a nice way to solve that as cargo will consider the unit changed if a depinfo file is missing

https://github.com/rust-lang/cargo/blob/9865dde6d0b55e4faf4d0dbb10a9c9814955fd1f/src/cargo/core/compiler/fingerprint.rs#L182-L184

@Alexendoo Alexendoo changed the title clippy.toml ignored if clippy results have been cached A newly created clippy.toml does not trigger a rebuild Nov 21, 2022
@awused
Copy link

awused commented Jul 13, 2023

This caused a lot of confusion for me today. I was setting CLIPPY_CONF_DIR to use a new global clippy config file and was very confused why it wasn't working.

More confusingly, clippy will fail instantly if CLIPPY_CONF_DIR is invalid or doesn't contain a clippy.toml/.clippy.toml, but it will not actually read, validate, or use those values until something triggers a rebuild, making me believe the problem was with the lint or the configuration option I was setting.

@Alexendoo
Copy link
Member

Thanks for pointing that out @awused, I've opened #11154 that will cause any changes to CLIPPY_CONF_DIR to trigger a rebuild

bors added a commit that referenced this issue Jul 13, 2023
Trigger a rebuild when `CLIPPY_CONF_DIR` changes

changelog: none

This is a fix for #9928 (comment), any time `CLIPPY_CONF_DIR` changes cargo will now rebuild the crate clippy is being run on, giving it a chance to lint with the (potentially) different config file

r? `@flip1995`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

3 participants