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

cargo-clippy unconditionally runs lints for path dependencies #1066

Closed
crumblingstatue opened this issue Jul 2, 2016 · 16 comments · Fixed by #1069
Closed

cargo-clippy unconditionally runs lints for path dependencies #1066

crumblingstatue opened this issue Jul 2, 2016 · 16 comments · Fixed by #1069
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@crumblingstatue
Copy link

Say we have this project:

Cargo.toml:

[package]
name = "haspathdep"
version = "0.1.0"

[features]
clippy = []

[dependencies.foodep]
path = "foodep"

src/lib.rs:

extern crate foodep;

#[cfg_attr(feature="clippy", allow(enum_variant_names))]
enum Sock {
    YellowSock,
}

pub fn utilize() {
    let _sock = Sock::YellowSock;
    let _spr = foodep::Sprite::ASprite;
}

foodep/Cargo.toml:

[package]
name = "foodep"
version = "0.1.0"

[features]
clippy = []

foodep/src/lib.rs:

// Triggers `enum_variant_names` lint.
// Let's just say I have no control over the naming,
// as this is a -sys crate generated with bindgen.
#[cfg_attr(feature="clippy", allow(enum_variant_names))]
pub enum Sprite {
    ASprite,
    BSprite,
}

When I run cargo clippy --features=clippy on foodep, it compiles without warnings, because of the conditional allow(enum_variant_names).

However, when I run cargo clippy --features=clippy on haspathdep, it also runs the clippy lints for foodep, but without taking into consideration that I have enabled --features=clippy.

$ cargo clippy --features=clippy
   Compiling foodep v0.1.0 (file:///tmp/haspathdep/foodep)
foodep/src/lib.rs:6:5: 6:12 warning: Variant name ends with the enum's name, #[warn(enum_variant_names)] on by default
foodep/src/lib.rs:6     ASprite,
                        ^~~~~~~
foodep/src/lib.rs:6:5: 6:12 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#enum_variant_names
foodep/src/lib.rs:7:5: 7:12 warning: Variant name ends with the enum's name, #[warn(enum_variant_names)] on by default
foodep/src/lib.rs:7     BSprite,
                        ^~~~~~~
foodep/src/lib.rs:7:5: 7:12 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#enum_variant_names
foodep/src/lib.rs:5:1: 8:2 warning: All variants have the same postfix: `Sprite`, #[warn(enum_variant_names)] on by default
foodep/src/lib.rs:5 pub enum Sprite {
                    ^
foodep/src/lib.rs:5:1: 8:2 help: remove the postfixes and use full paths to the variants instead of glob imports
foodep/src/lib.rs:5:1: 8:2 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#enum_variant_names
   Compiling haspathdep v0.1.0 (file:///tmp/haspathdep)

@mcarton mcarton added the C-bug Category: Clippy is not doing the correct thing label Jul 2, 2016
@oli-obk oli-obk self-assigned this Jul 4, 2016
@anderejd
Copy link

anderejd commented Oct 2, 2018

Clippy seems to be running on all path dependencies again, reopen this issue?

@oli-obk oli-obk reopened this Oct 2, 2018
@fpoli
Copy link

fpoli commented Nov 20, 2018

It seems that Clippy looks for the argument --emit=dep-info,metadata to decide if it's run on a dependency:
https://github.com/rust-lang-nursery/rust-clippy/blob/3a11cd428902feafdc70c279d2dbc950f580db3f/src/driver.rs#L87-L91
Why is that argument special?

@oli-obk
Copy link
Contributor

oli-obk commented Nov 20, 2018

That's just a hack to detect that we're in the final rustc invocation of cargo check. cargo check runs rustc for all dependencies (where we don't want to lint) and then at the end runs rustc for the final crate (where we inject our lints).

I want to build a general way for custom drivers to be run on the final crate only (and without such flag parsing hacks), but I haven't gotten around to it.

@fpoli
Copy link

fpoli commented Nov 21, 2018

A general way would be super useful for custom drivers! I'm also looking for a reliable solution for a driver that we are building, so if I find something useful I'll share.

By the way, is that the only check? Looking at the rustc invocations on the regex crate there are multiple dependencies for which --emit=dep-info,metadata is used, but somehow Clippy only reports lints for regexp.

~/git/regex$ cargo clean && cargo +nightly check --verbose
    Updating crates.io index
   Compiling version_check v0.1.5
    Checking libc v0.2.43
    Checking cfg-if v0.1.6
   Compiling regex v1.0.6 (/home/fpoli/git/regex)
    Checking lazy_static v1.2.0
    Checking ucd-util v0.1.3
    Checking utf8-ranges v1.0.2
     Running `rustc --crate-name version_check /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/version_check-0.1.5/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=fd2828a45242e207 -C extra-filename=-fd2828a45242e207 --out-dir /home/fpoli/git/regex/target/debug/deps -L dependency=/home/fpoli/git/regex/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name libc /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.43/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="use_std"' -C metadata=a37d9a67eea2ecf1 -C extra-filename=-a37d9a67eea2ecf1 --out-dir /home/fpoli/git/regex/target/debug/deps -L dependency=/home/fpoli/git/regex/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name cfg_if /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-0.1.6/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=6b4f6ef9b7aab446 -C extra-filename=-6b4f6ef9b7aab446 --out-dir /home/fpoli/git/regex/target/debug/deps -L dependency=/home/fpoli/git/regex/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name build_script_build build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="use_std"' -C metadata=1826c34f47144207 -C extra-filename=-1826c34f47144207 --out-dir /home/fpoli/git/regex/target/debug/build/regex-1826c34f47144207 -C incremental=/home/fpoli/git/regex/target/debug/incremental -L dependency=/home/fpoli/git/regex/target/debug/deps`
     Running `rustc --crate-name lazy_static /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.2.0/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=bf52e92cfc730485 -C extra-filename=-bf52e92cfc730485 --out-dir /home/fpoli/git/regex/target/debug/deps -L dependency=/home/fpoli/git/regex/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name ucd_util /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/ucd-util-0.1.3/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=74e08e7bce386d40 -C extra-filename=-74e08e7bce386d40 --out-dir /home/fpoli/git/regex/target/debug/deps -L dependency=/home/fpoli/git/regex/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name utf8_ranges /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/utf8-ranges-1.0.2/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=cc518a4bcb52c5ce -C extra-filename=-cc518a4bcb52c5ce --out-dir /home/fpoli/git/regex/target/debug/deps -L dependency=/home/fpoli/git/regex/target/debug/deps --cap-lints allow`
    Checking thread_local v0.3.6
     Running `rustc --crate-name thread_local /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/thread_local-0.3.6/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=3c760cea5e58bb7d -C extra-filename=-3c760cea5e58bb7d --out-dir /home/fpoli/git/regex/target/debug/deps -L dependency=/home/fpoli/git/regex/target/debug/deps --extern lazy_static=/home/fpoli/git/regex/target/debug/deps/liblazy_static-bf52e92cfc730485.rmeta --cap-lints allow`
    Checking regex-syntax v0.6.3 (/home/fpoli/git/regex/regex-syntax)
     Running `rustc --crate-name regex_syntax regex-syntax/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=37c441d0dc4a486f -C extra-filename=-37c441d0dc4a486f --out-dir /home/fpoli/git/regex/target/debug/deps -C incremental=/home/fpoli/git/regex/target/debug/incremental -L dependency=/home/fpoli/git/regex/target/debug/deps --extern ucd_util=/home/fpoli/git/regex/target/debug/deps/libucd_util-74e08e7bce386d40.rmeta`
   Compiling memchr v2.1.1
     Running `rustc --crate-name build_script_build /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/memchr-2.1.1/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="libc"' --cfg 'feature="use_std"' -C metadata=18c251372677993e -C extra-filename=-18c251372677993e --out-dir /home/fpoli/git/regex/target/debug/build/memchr-18c251372677993e -L dependency=/home/fpoli/git/regex/target/debug/deps --extern version_check=/home/fpoli/git/regex/target/debug/deps/libversion_check-fd2828a45242e207.rlib --cap-lints allow`
     Running `/home/fpoli/git/regex/target/debug/build/regex-1826c34f47144207/build-script-build`
     Running `/home/fpoli/git/regex/target/debug/build/memchr-18c251372677993e/build-script-build`
     Running `rustc --crate-name memchr /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/memchr-2.1.1/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="libc"' --cfg 'feature="use_std"' -C metadata=d13d58bc354ac449 -C extra-filename=-d13d58bc354ac449 --out-dir /home/fpoli/git/regex/target/debug/deps -L dependency=/home/fpoli/git/regex/target/debug/deps --extern cfg_if=/home/fpoli/git/regex/target/debug/deps/libcfg_if-6b4f6ef9b7aab446.rmeta --extern libc=/home/fpoli/git/regex/target/debug/deps/liblibc-a37d9a67eea2ecf1.rmeta --cap-lints allow --cfg memchr_runtime_simd --cfg memchr_runtime_sse2 --cfg memchr_runtime_sse42 --cfg memchr_runtime_avx`
    Checking aho-corasick v0.6.9
     Running `rustc --crate-name aho_corasick /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/aho-corasick-0.6.9/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=3d836bdb66a9b66b -C extra-filename=-3d836bdb66a9b66b --out-dir /home/fpoli/git/regex/target/debug/deps -L dependency=/home/fpoli/git/regex/target/debug/deps --extern memchr=/home/fpoli/git/regex/target/debug/deps/libmemchr-d13d58bc354ac449.rmeta --cap-lints allow`
     Running `rustc --crate-name regex src/lib.rs --color always --crate-type lib --emit=dep-info,metadata -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="use_std"' -C metadata=8f26a9e296e994dc -C extra-filename=-8f26a9e296e994dc --out-dir /home/fpoli/git/regex/target/debug/deps -C incremental=/home/fpoli/git/regex/target/debug/incremental -L dependency=/home/fpoli/git/regex/target/debug/deps --extern aho_corasick=/home/fpoli/git/regex/target/debug/deps/libaho_corasick-3d836bdb66a9b66b.rmeta --extern memchr=/home/fpoli/git/regex/target/debug/deps/libmemchr-d13d58bc354ac449.rmeta --extern regex_syntax=/home/fpoli/git/regex/target/debug/deps/libregex_syntax-37c441d0dc4a486f.rmeta --extern thread_local=/home/fpoli/git/regex/target/debug/deps/libthread_local-3c760cea5e58bb7d.rmeta --extern utf8_ranges=/home/fpoli/git/regex/target/debug/deps/libutf8_ranges-cc518a4bcb52c5ce.rmeta --cfg regex_runtime_teddy_ssse3 --cfg regex_runtime_teddy_avx2`
    Finished dev [unoptimized + debuginfo] target(s) in 8.21s

@yaahc
Copy link
Member

yaahc commented Nov 28, 2018

I'm not sure if this is related but it seems like it might be so I'm gonna leave this info here in case it helps.

I have this project https://github.com/yaahallo/gameoff where if I run stable clippy it errors out on some of the dependencies

error[E0658]: scoped lint `clippy::while_let_on_iterator` is experimental (see issue #44690)
    --> /home/jlusby/.cargo/registry/src/github.com-1ecc6299db9ec823/slice-deque-0.1.14/src/lib.rs:1697:19
     |
1697 |             allow(clippy::while_let_on_iterator)
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Notably, my project is split into multiple crates in a workspace using a path dependency from the lib crate to the binary crate.

I wouldn't expect clippy to run lints on any of my dependencies (other than the path one).

I tried running clippy specifically from the lib crate game-core and it still had the same problem. I then tried removing the workplace Cargo.toml and rebuilding in the lib crate, based on the idea that the workspace and bin crate with a path dependency to the lib might somehow still be involved, but the error persisted.

This leads me to believe it's not related to the fact that its a path dependency, and I'm not honestly sure clippy isn't expected to lint every dependency. But it seemed weird so I figured I'd bring it up.

@elichai
Copy link
Contributor

elichai commented Dec 31, 2018

I'm experiencing the same behavior even on latest nightly

dfrankland added a commit to dfrankland/servo-css-parser that referenced this issue Mar 6, 2019
Cargo tries to lint all of the path dependencies, so it's disabled for now

rust-lang/rust-clippy#1066
@steveklabnik
Copy link
Member

Ran into this today, and found it very surprising.

@Manishearth
Copy link
Member

The permanent fix for this is #3837, once we have that we can customize this behavior in cargo.

@nrc
Copy link
Member

nrc commented Jul 23, 2019

I want to build a general way for custom drivers to be run on the final crate only (and without such flag parsing hacks), but I haven't gotten around to it.

If this is still the problem blocking fixing this, then there is a solution to use the Cargo API - there is a Command API which gives a way to distinguish the final/main crate from deps. (I don't recall the details, but the RLS uses it).

@ehuss
Copy link
Contributor

ehuss commented Jul 23, 2019

This is fixed on latest master of cargo for clippy-preview (via rust-lang/cargo#7069). I'll be updating nightly soon. Migrating to clippy-preview is tracked in #3837.

@yaahc
Copy link
Member

yaahc commented Jul 24, 2019

Ooh god, I accidentally fixed an issue I participated in a year earlier without even knowing. What are the chances...

@dvc94ch
Copy link

dvc94ch commented Jan 2, 2020

I think there's been a regression

cargo-clippy --version
clippy 0.0.212 (c8e3cfb 2019-10-28)

@flip1995
Copy link
Member

flip1995 commented Jan 2, 2020

You have to use clippy-preview, which is the cargo integrated (unstable) version of Clippy. We hope, that this will be the default soon.

@ghost
Copy link

ghost commented May 24, 2020

I'm using clippy version clippy 0.0.212 (28197b6 2020-04-29) with:

$ rustc -vV
rustc 1.45.0-nightly (fa51f810e 2020-04-29)
binary: rustc
commit-hash: fa51f810e5b9254904b92660e7280b7d6a46f112
commit-date: 2020-04-29
host: x86_64-unknown-linux-gnu
release: 1.45.0-nightly
LLVM version: 9.0

I have a project with one path dependency (foo = { path = "../foo" }) and clippy always lints it.
And #[allow(clippy::all)] doesn't solved my issue. How can I do it right?

@ryanavella
Copy link

I'm seeing the same thing as @notoria. Am I missing something?

> rustc -vV
rustc 1.50.0-nightly (825637983 2020-11-18)
binary: rustc
commit-hash: 8256379832b5ecb7f71e8c5e2018446482223c12
commit-date: 2020-11-18
host: x86_64-pc-windows-msvc
release: 1.50.0-nightly

> rustup -V
rustup 1.22.1 (b01adbbc3 2020-07-08)

> cargo-clippy -V
clippy 0.0.212 (82563798 2020-11-18)

> rustup component add clippy-preview
info: component 'clippy' for target 'x86_64-pc-windows-msvc' is up to date

@ehuss
Copy link
Contributor

ehuss commented Nov 23, 2020

@ryanavella Use cargo +nightly clippy -Zunstable-options, see #3837 (comment).

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

Successfully merging a pull request may close this issue.