11

I'm trying to run clippy for the first time (I know.. I really should have done it by now eh?) and I am facing some errors.

The project I'm trying to lint depends on Piston and it compiles and runs successfully. However, when I run clippy as described in the README:

rustup run nightly cargo clippy

It looks like it starts trying to build Piston and reports errors like this:

error[E0433]: failed to resolve. Use of undeclared type or module `gfx`
  --> /Users/Simon/.cargo/registry/src/github.com-    1ecc6299db9ec823/piston2d-gfx_graphics-0.31.2/src/back_end.rs:31:10
   |
31 |     pos: gfx::VertexBuffer<PositionFormat>,
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use of undeclared type or module `gfx`

error[E0433]: failed to resolve. Use of undeclared type or module     `gfx`
  --> /Users/Simon/.cargo/registry/src/github.com-    1ecc6299db9ec823/piston2d-gfx_graphics-0.31.2/src/back_end.rs:32:12
   |
32 |     color: gfx::VertexBuffer<ColorFormat>,
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use of undeclared type or module `gfx`

error[E0433]: failed to resolve. Use of undeclared type or module `gfx`
  --> /Users/Simon/.cargo/registry/src/github.com-1ecc6299db9ec823/piston2d-gfx_graphics-0.31.2/src/back_end.rs:33:19
   |
33 |     blend_target: gfx::BlendTarget<gfx::format::Srgba8>,
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use of undeclared type or module `gfx`

error[E0433]: failed to resolve. Use of undeclared type or module `gfx`
  --> /Users/Simon/.cargo/registry/src/github.com-1ecc6299db9ec823/piston2d-gfx_graphics-0.31.2/src/back_end.rs:33:36
   |
33 |     blend_target: gfx::BlendTarget<gfx::format::Srgba8>,
   |                                    ^^^^^^^^^^^^^^^^^^^ Use of undeclared type or module `gfx`

error[E0433]: failed to resolve. Use of undeclared type or module `gfx`
  --> /Users/Simon/.cargo/registry/src/github.com-1ecc6299db9ec823/piston2d-gfx_graphics-0.31.2/src/back_end.rs:34:21
   |
34 |     stencil_target: gfx::StencilTarget<gfx::format::DepthStencil>,
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use of undeclared type or module `gfx`

How can I tell clippy to not build Piston and/or lint it? How can I just have it build my project and lint my code?

cargo build builds the project successfully from the same folder.

I haven't dug deep into clippy's code, but I assumed it worked off an AST and didn't actually build the binaries... it seems I was incorrect?

Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138

2 Answers2

7

How can I tell clippy to not build Piston and/or lint it?

You can't.

Clippy needs to build all dependencies to be able to lint your project. This is because only a few lints run solely on the AST. Most lints run on the HIR and also require type information.

Unfortunately I cannot reproduce your error on piston_window v0.57.0, but that version pulls in piston2d-gfx_graphics v0.33.1, which is newer than the 0.31.2 that you are using. Maybe updating will solve your issues.

oli_obk
  • 28,729
  • 6
  • 82
  • 98
  • Thanks. I actually never thought to check for an update. I converted to an asterisk for the versions of all of the Piston crates and ran `cargo update` and ... wouldn't you know it... `rustup run nightly cargo clippy` is now returning actual clippy results. Thanks for the tip! – Simon Whitehead Nov 10 '16 at 13:19
  • Maybe it could *build* all the dependencies it needed, but have an option to NOT flag warnings/errors outside the project code that you cannot fix? – Andrew Mackenzie Apr 29 '20 at 13:46
  • @AndrewMackenzie that's the way I assumed it would work, but I can't find any such flag/option for cargo check or cargo clippy, so a 3rd party issue prevents clippy from even checking my local code. afaict – danda Feb 08 '21 at 23:02
  • @danda - yep, that seems to be the way it is and we just have to live with it. – Andrew Mackenzie Mar 18 '21 at 17:44
1

At some point, Clippy gained the --no-deps option, which according to the docs,

Run Clippy only on the given crate, without linting the dependencies

That should do the trick for the problem in this question.

womble
  • 12,033
  • 5
  • 52
  • 66