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
10.89k stars 1.46k forks source link

clippy-driver acts as a bogus rustc wrapper #12697

Open RalfJung opened 3 weeks ago

RalfJung commented 3 weeks ago

This came up in https://github.com/cuviper/autocfg/issues/58, and may also become more relevant with https://github.com/rust-lang/cargo/pull/13659 and https://github.com/djc/rustc-version-rs/issues/45:

Apparently, cargo clippy sets clippy-driver as RUSTC_WORKSPACE_WRAPPER, but that wrapper behaves incorrectly, i.e. it does not always properly forward everything to rustc:

$ clippy-driver rustc --version                                              
clippy 0.1.79 (f9b16149 2024-04-19)

$ clippy-driver rustc --version --verbose
clippy 0.1.79 (f9b16149 2024-04-19)

$ clippy-driver rustc --rustc --version  
rustc 1.79.0-nightly (f9b161492 2024-04-19)

$ clippy-driver rustc --rustc --version --verbose
rustc 1.79.0-nightly (f9b161492 2024-04-19)
binary: rustc
commit-hash: f9b16149208c8a8a349c32813312716f6603eb6f
commit-date: 2024-04-19
host: aarch64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.4

$ clippy-driver rustc -V
clippy 0.1.79 (f9b16149 2024-04-19)

$ clippy-driver rustc -Vv
rustc 1.79.0-nightly (f9b161492 2024-04-19)
binary: rustc
commit-hash: f9b16149208c8a8a349c32813312716f6603eb6f
commit-date: 2024-04-19
host: aarch64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.4

$ clippy-driver rustc -vV
rustc 1.79.0-nightly (f9b161492 2024-04-19)
binary: rustc
commit-hash: f9b16149208c8a8a349c32813312716f6603eb6f
commit-date: 2024-04-19
host: aarch64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.4

I am surprised that clippy-driver is even being set as RUSTC_WORKSPACE_WRAPPER; Miri (which has a similar problem to solve) does not do that. Instead cargo-miri sets itself as RUSTC_WRAPPER so that it can then dispatch to the driver as appropriate. Either way can work, but whatever is set as RUSTC_WRAPPER/RUSTC_WORKSPACE_WRAPPER should behave like a proper wrapper and not intercept --version queries.

taiki-e commented 3 weeks ago

cargo clippy sets clippy-driver as RUSTC_WRAPPER

(Not related to this bug itself, but AFAIK, as said in https://github.com/cuviper/autocfg/issues/58#issuecomment-2067625980, cargo clippy sets clippy-driver as RUSTC_WORKSPACE_WRAPPER, not RUSTC_WRAPPER.)

RalfJung commented 3 weeks ago

(Not related to this bug itself, but AFAIK, as said in cuviper/autocfg#58 (comment), cargo clippy sets clippy-driver as RUSTC_WORKSPACE_WRAPPER, not RUSTC_WRAPPER.)

Ah, sorry for that -- fixed.