rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.34k stars 1.53k forks source link

clippy handles vendored dependencies differently from crates.io dependencies #9350

Closed ericseppanen closed 2 years ago

ericseppanen commented 2 years ago

Summary

I have noticed that one of my dependencies has compiler warnings. This doesn't usually affect how I use Clippy, because those warnings are suppressed.

However, when I tried to vendor that dependency (checking it in to git in a path outside my project [^1], and changing Cargo.toml to use some_crate = { path = "../vendored/that_crate" }), I find that now Clippy is reporting the compiler warnings from inside that dependency.

I have searched for similar reports of this problem, but didn't see any. #3025 seems possibly related, but doesn't address this issue directly.

[^1]: I've tried this with and without a cargo workspace, and get the same result.

[^2]: To get the vendored copy: git clone -b v0.0.14 https://github.com/nbigaouette/onnxruntime-rs.git

Reproducer

I started a new project, and specified the same dependency in 3 different ways.[^2] Only with the third one (vendored to a local path) does clippy report that crates' warnings when running cargo clippy from within my project.

[dependencies]
# No warnings from clippy if I do this
#onnxruntime = "0.0.14"

# No warnings from clippy if I do this
#onnxruntime = { git = "https://github.com/nbigaouette/onnxruntime-rs.git", tag = "v0.0.14" }

# Clippy prints warnings if I do this
onnxruntime = { path = "../vendored/onnxruntime-rs/onnxruntime" }

Version

rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: x86_64-unknown-linux-gnu
release: 1.63.0
LLVM version: 14.0.5

Additional Labels

No response

ericseppanen commented 2 years ago

cargo check has the same behavior. Perhaps this is a dupe of cargo bug #8546?

Alexendoo commented 2 years ago

It is behaviour from cargo yeah, it's which crates RUSTC_WORKSPACE_WRAPPER apply to.

For vendoring dependencies usually [source] is used (as output by cargo vendor), but on the clippy side if you do want to ignore path dependencies/workspace members --no-deps should work

ericseppanen commented 2 years ago

... on the clippy side if you do want to ignore path dependencies/workspace members --no-deps should work

That doesn't work in this case because the warnings are actually compiler warnings, not clippy lints. Feel free to try the "reproducer" example above to demonstrate this.

ericseppanen commented 2 years ago

Closing in favor of cargo bug #8546.