-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix x.py clippy
#77351
Fix x.py clippy
#77351
Conversation
Update: the issue is that clippy was looking at |
Hm |
Hm, so I think this should be fixed in clippy. If it's using the wrong rustc this is at best a temporary patch - eventually a more serious problem than just the sysroot will arise, though I'm not entirely sure why clippy is running rustc at all. We might also want to have x.py download clippy on demand (when running clippy) so that there's less version problems. |
This isn't a clippy version issue, this is a rustc version issue. Clippy runs the rustc in $PATH when it should run
See rust-lang/rust-clippy#3546
Ok, I'll do that here (cc @flip1995). I'm going to keep the bootstrap hack for now so I don't have to build rustc/clippy from source, but this is the fix: diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs
index f4f2259ce..5e688d72d 100644
--- a/src/driver.rs
+++ b/src/driver.rs
@@ -323,7 +323,7 @@ pub fn main() {
toolchain_path(home, toolchain)
})
.or_else(|| {
- Command::new("rustc")
+ Command::new(env::var("RUSTC").unwrap_or("rustc"))
.arg("--print")
.arg("sysroot")
.output() |
Clippy needs some // Get the sysroot, looking from most specific to this invocation to the least:
// - command line
// - runtime environment
// - SYSROOT
// - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
// - sysroot from rustc in the path
// - compile-time environment
// - SYSROOT
// - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN For the " |
Right now, yes, there's no version issue, but stable/nightly clippy isn't guaranteed to work. Anyway, I'm fine with merging this for now, r=me. |
Sorry, I didn't say - this does not fix
I think it might need more of the logic in |
a5e2fda
to
dccd80e
Compare
Ok, this is actually working now :) Giant thank you to @ehuss for all the help with bootstrap! |
The current error for
I figure that can be fixed in a follow-up, though. |
Found while working on rust-lang#77351; these are just the ones that could be fixed automatically.
src/bootstrap/builder.rs
Outdated
} | ||
}) { | ||
eprintln!( | ||
"error: `x.py clippy` requires a nightly host `rustc` toolchain with the `clippy` component" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like the wrong recommendation. Nightly clippy is not guaranteed to work; beta clippy is much more likely to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nightly Clippy is always available, since we use git subtree
for Clippy. It may have a few more FPs, but generally it should work. Or am I misunderstanding something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nightly clippy is always available but may not work on the rustc tree -- it's usually outdated by several PRs (at most points in the day) which means that there's a pretty high likelihood of it not understanding some library feature or failing on stabilization etc. Beta clippy, like beta rustc, is something we're much more prepared for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not able to get this to work with a beta clippy.
error[E0522]: definition of an unknown language item: `array`
--> library/core/src/array/mod.rs:379:1
|
379 | #[lang = "array"]
| ^^^^^^^^^^^^^^^^^ definition of unknown language item `array`
... various other E0522 errors ...
error[E0118]: no base type found for inherent implementation
--> library/core/src/array/mod.rs:380:25
|
380 | impl<T, const N: usize> [T; N] {
| ^^^^^^ impl requires a base type
error: aborting due to 20 previous errors; 53 warnings emitted
This is with cfg=bootstrap
. I think it's related to not setting RUSTC
somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I am okay with us merging fixes to nightly clippy working, but I am unwilling to actually actively recommend nightly. I think that RUSTC getting set just needs to get fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried setting RUSTC to no effect, I think because there's no CLIPPY analogue to RUSTC or RUSTFMT.
I'm not sure exactly what needs to happen to get beta clippy to work. Why does x.py check
work with beta rustc when x.py clippy
doesn't? I don't know what's going wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This started working after the beta bump, although I'm not sure why ... maybe I had an old version of beta or something? Anyway, I tested with both nightly and beta and it seems to be working.
…-Simulacrum Fix some clippy lints Found while working on rust-lang#77351; these are just the ones that could be fixed automatically.
…-Simulacrum Fix some clippy lints Found while working on rust-lang#77351; these are just the ones that could be fixed automatically.
This comment has been minimized.
This comment has been minimized.
de67002
to
d78ac2c
Compare
This comment has been minimized.
This comment has been minimized.
Clippy does its own runtime detection of the sysroot, which was incorrect in this case (it used the beta sysroot). This overrides the sysroot to use `stage0-sysroot` instead. - Get `x.py clippy` to work on nightly - Give a nice error message if nightly clippy isn't installed
|
Fix some more clippy warnings Found while working on rust-lang#77351. It turns out that `x.py clippy --fix` does work on that branch as long as you pass `CARGOFLAGS=--lib`.
ping @Mark-Simulacrum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still pretty unhappy with this additional code being added to fix this, but it's not in the critical complicated pieces of bootstrap sufficiently for me to block it.
r=me with comments resolved (they're both nit-ish so I don't feel strongly about re-reviewing unless you think that's necessary)
src/bootstrap/builder.rs
Outdated
let host_version = Command::new("rustc").arg("--version").output().map_err(|_| ()); | ||
let output = host_version.and_then(|output| { | ||
if output.status.success() | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This brace looks like it should be on the previous line (i.e., if ... {\n
)
src/bootstrap/builder.rs
Outdated
@@ -850,7 +850,42 @@ impl<'a> Builder<'a> { | |||
cargo.args(s.split_whitespace()); | |||
} | |||
rustflags.env("RUSTFLAGS_BOOTSTRAP"); | |||
rustflags.arg("--cfg=bootstrap"); | |||
if cmd == "clippy" { | |||
// clippy overwrites any sysroot we pass on the command line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused, this sysroot is being passed on the command line? If that gets overwritten, then what's the point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is wrong - it gets overwritten if we pass it to cargo, not if we pass it to clippy.
Here's the error for rustdoc: ``` Checking rustdoc artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu) error: no library targets found in package `rustdoc-tool` ```
90d6853
to
8d2fa72
Compare
@bors r+ |
📌 Commit 8d2fa72 has been approved by |
📌 Commit 8d2fa72 has been approved by |
…acrum Fix `x.py clippy` I don't think this ever worked. Fixes rust-lang#77309. `--fix` support is a work in progress, but works for a very small subset of `libtest`. This works by using the host `cargo-clippy` driver; it does not use `stage0.txt` at all. To mitigate confusion from this, it gives an error if you don't have `rustc +nightly` as the default rustc in `$PATH`. Additionally, it means that bootstrap can't set `RUSTC`; this makes it no longer possible for clippy to detect the sysroot itself. Instead, bootstrap passes the sysroot to cargo. r? `@ghost`
☀️ Test successful - checks-actions |
I don't think this ever worked.
Fixes #77309.
--fix
support is a work in progress, but works for a very small subset oflibtest
.This works by using the host
cargo-clippy
driver; it does not usestage0.txt
at all. To mitigate confusion from this, it gives an error if you don't haverustc +nightly
as the default rustc in$PATH
. Additionally, it means that bootstrap can't setRUSTC
; this makes it no longer possible for clippy to detect the sysroot itself. Instead, bootstrap passes the sysroot to cargo.r? @ghost