-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
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)
Cogitri, dfrankland and Tim-Zhang
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
anderejd commentedon Oct 2, 2018
Clippy seems to be running on all path dependencies again, reopen this issue?
fpoli commentedon 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 commentedon Nov 20, 2018
That's just a hack to detect that we're in the final
rustc
invocation ofcargo check
.cargo check
runsrustc
for all dependencies (where we don't want to lint) and then at the end runsrustc
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 commentedon 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 theregex
crate there are multiple dependencies for which--emit=dep-info,metadata
is used, but somehow Clippy only reports lints forregexp
.~/git/regex$ cargo clean && cargo +nightly check --verbose
yaahc commentedon 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
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 commentedon Dec 31, 2018
I'm experiencing the same behavior even on latest nightly
Disable clippy
steveklabnik commentedon Jun 17, 2019
Ran into this today, and found it very surprising.
Manishearth commentedon Jun 17, 2019
The permanent fix for this is #3837, once we have that we can customize this behavior in cargo.
nrc commentedon Jul 23, 2019
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 commentedon 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 commentedon Jul 24, 2019
Ooh god, I accidentally fixed an issue I participated in a year earlier without even knowing. What are the chances...
dvc94ch commentedon Jan 2, 2020
I think there's been a regression
flip1995 commentedon 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 commentedon May 24, 2020
I'm using
clippy
versionclippy 0.0.212 (28197b6 2020-04-29)
with:I have a project with one path dependency (
foo = { path = "../foo" }
) andclippy
always lints it.And
#[allow(clippy::all)]
doesn't solved my issue. How can I do it right?ryanavella commentedon Nov 19, 2020
I'm seeing the same thing as @notoria. Am I missing something?
ehuss commentedon Nov 23, 2020
@ryanavella Use
cargo +nightly clippy -Zunstable-options
, see #3837 (comment).