Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude dependencies when running Clippy

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?

like image 521
Simon Whitehead Avatar asked Nov 10 '16 00:11

Simon Whitehead


1 Answers

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.

like image 166
oli_obk Avatar answered Sep 18 '22 11:09

oli_obk