Skip to content

cargo-clippy unconditionally runs lints for path dependencies #1066

Closed
@crumblingstatue

Description

@crumblingstatue

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)

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions