Clippy getting started question

I've got clippy installed and apparently working but when I run it, it produces no warnings:

0 (master) ./rust/test1 $  cargo clippy
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
0 (master) ./rust/test1 $

I decided it was possible (though highly unlikely!) my code had no lint in it so, after reviewing https://github.com/rust-lang-nursery/rust-clippy#usage, I inserted an example lint called "absurd_extreme_comparisons", where I do vec.len() <= 0, re-running clippy still produced no warnings.

According to the read.me, the linty code I added falls under the category of:
clippy_correctness (code that is just outright wrong or very very useless)

I didn't see anything in the readme that explained exactly how to turn this on. So I tried modifying one of my source files using the description under "Allowing/denying lints" to see if that enabled it:
#![warn(clippy_correctness)]

Again no luck... help?

:smile:

Check your up to date is first thing that comes to mind.
cargo +nightly clippy -V
0.0.212

Looks like I have the right version:

(master) ./rust/test1 $ cargo +nightly clippy -V
0.0.212

I tried the compiler to see what it thought about the clippy_correctness line and it didn't like it at all:

(master) ./rust/test1 $ cargo build
   Compiling test1 v0.1.0 (file:///Users/kgoodman/dev/rust/test1)
warning: unknown lint: `clippy_correctness`                              ] 0/1: test1
 --> src/main.rs:3:9
  |
3 | #![warn(clippy_correctness)]
  |         ^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unknown_lints)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 1.14s
(master) ./rust/test1 $ cargo clippy
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
(master) ./rust/test1 $

Can someone confirm whether this lint should be reported by clippy without any code change or toml configuration change? i.e. do I have to tell clippy, somehow, that I want it to report clippy_correctness lints, or should simply typing cargo clippy at the shell be enough?

I created a new binary project on my machine with the following code and no further config changes:

fn main() {
    let vec = vec![1];

    if vec.len() <= 0 {
        println!("testing, testing");
    }
}

Running cargo +nightly clippy gave me the following output:

error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
 --> src\main.rs:4:8
  |
4 |     if vec.len() <= 0 {
  |        ^^^^^^^^^^^^^^
  |
  = note: #[deny(absurd_extreme_comparisons)] on by default
  = help: because 0 is the minimum value for this type, the case where the two sides are not equal never occurs, consider using vec.len() == 0 instead
  = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#absurd_extreme_comparisons

error: aborting due to previous error
1 Like

Thanks - that seems to confirm the way I'm invoking clippy should have produced some output. Must be something mixed up in my tool configuration.

1 Like

It looks like an instance of this clippy bug. The workaround for now is to run touch src/main.rs right before running clippy.

2 Likes

Yep - that did the trick - thanks!