-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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: Make auto-fix note work with clippy
#11399
Conversation
r? @ehuss (rustbot has picked a reviewer for you, use r? to override) |
src/cargo/core/compiler/job_queue.rs
Outdated
// check if `RUSTC_WORKSPACE_WRAPPER` is set. `clippy` sets | ||
// this when being ran so it can partially be identified | ||
// when this is set. | ||
let command = if rustc_workspace_wrapper.is_some() { |
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.
Unfortunately clippy isn't the only tool which sets RUSTC_WORKSPACE_WRAPPER
. I think some other approach will be needed here.
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 worried about that, I was hoping it would be fine since it was used before. The only thing I can think of is using CLIPPY_ARGS
, which appears to pass the test I wrote. I will update it to that.
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.
After some discussion, it was decided that RUSTC_WORKSPACE_WRAPPER
would be better as it is already agreed upon by clippy
and cargo
. Since other things can use RUSTC_WORKSPACE_WRAPPER
, we look for a wrapper named clippy-driver
.
e8e9b8b
to
12f0c8a
Compare
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.
Looks goog to me. Thanks!
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.
Looks good! Just some tiny not important stuff.
src/cargo/core/compiler/job_queue.rs
Outdated
let command = match rustc_workspace_wrapper { | ||
#[cfg(windows)] | ||
Some(wrapper) if wrapper.ends_with("clippy-driver.exe") => { | ||
"cargo clippy --fix" | ||
} | ||
#[cfg(not(windows))] | ||
Some(wrapper) if wrapper.ends_with("clippy-driver") => "cargo clippy --fix", | ||
_ => "cargo fix", | ||
}; |
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.
(nit)
let command = match rustc_workspace_wrapper { | |
#[cfg(windows)] | |
Some(wrapper) if wrapper.ends_with("clippy-driver.exe") => { | |
"cargo clippy --fix" | |
} | |
#[cfg(not(windows))] | |
Some(wrapper) if wrapper.ends_with("clippy-driver") => "cargo clippy --fix", | |
_ => "cargo fix", | |
}; | |
let clippy = std::ffi::OsStr::new("clippy-driver"); | |
let command = match rustc_workspace_wrapper.as_ref().and_then(|x| x.file_stem()) | |
{ | |
Some(wrapper) if wrapper == clippy => "cargo clippy --fix", | |
_ => "cargo fix", | |
}; | |
src/cargo/core/compiler/job_queue.rs
Outdated
" (run `{} --{}` to apply {})", | ||
command, args, suggestions |
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.
(nit)
" (run `{} --{}` to apply {})", | |
command, args, suggestions | |
" (run `{command} --{args}` to apply {suggestions})" |
12f0c8a
to
857aa32
Compare
857aa32
to
33c3208
Compare
Thanks! @bors r+ |
☀️ Test successful - checks-actions |
11 commits in cc0a320879c17207bbfb96b5d778e28a2c62030d..c994a4a638370bc7e0ffcbb0e2865afdfa7d4415 2022-12-14 14:46:57 +0000 to 2022-12-18 21:50:58 +0000 - Fix examples of proc-macro crates being scraped for examples (rust-lang/cargo#11497) - Enable triagebot's relabel functionality (rust-lang/cargo#11498) - Revert "temporarily disable test `lto::test_profile`" (rust-lang/cargo#11495) - Bump to 0.69.0, update changelog (rust-lang/cargo#11493) - Fix typo (rust-lang/cargo#11491) - Display CPU info in CI (rust-lang/cargo#11488) - Fix collision_doc_profile test error (rust-lang/cargo#11489) - fix: Make auto-fix note work with `clippy` (rust-lang/cargo#11399) - fix(add): use the possessive in error message (rust-lang/cargo#11483) - Document home crate in contrib docs (rust-lang/cargo#11481) - Split up registry documentation into multiple sections (rust-lang/cargo#11480)
Update cargo 11 commits in cc0a320879c17207bbfb96b5d778e28a2c62030d..c994a4a638370bc7e0ffcbb0e2865afdfa7d4415 2022-12-14 14:46:57 +0000 to 2022-12-18 21:50:58 +0000 - Fix examples of proc-macro crates being scraped for examples (rust-lang/cargo#11497) - Enable triagebot's relabel functionality (rust-lang/cargo#11498) - Revert "temporarily disable test `lto::test_profile`" (rust-lang/cargo#11495) - Bump to 0.69.0, update changelog (rust-lang/cargo#11493) - Fix typo (rust-lang/cargo#11491) - Display CPU info in CI (rust-lang/cargo#11488) - Fix collision_doc_profile test error (rust-lang/cargo#11489) - fix: Make auto-fix note work with `clippy` (rust-lang/cargo#11399) - fix(add): use the possessive in error message (rust-lang/cargo#11483) - Document home crate in contrib docs (rust-lang/cargo#11481) - Split up registry documentation into multiple sections (rust-lang/cargo#11480) r? `@ghost`
feat: stabilize auto fix note A note that some warnings could be fixed by running a `cargo fix` command was added in #10989 and made to work with `clippy` in #11399. It has only been turned on for `nightly` builds so far; this PR would make it show on `stable`. The original motivation for making this note `nightly` only, was to [allow for iteration](#10976 (comment)) on the message output. There has yet to be any feedback on the message format in the time that it has been on `nightly`. This was brought up in a recent cargo team meeting and it was thought that we should move forward with showing this on `stable`. close #10976
Someone pointed out that the suggestion to run
cargo --fix
did not work properly forcargo clippy
. This makes sure the correct command to run is output when running undercargo clippy
.This is done by checking if the
RUSTC_WORKSPACE_WRAPPER
environment variable is set, sinceclippy
sets this every run. Since other things can useRUSTC_WORKSPACE_WRAPPER
, we look for a wrapper namedclippy-driver
.Since
clippy
might not be available everywherecargo
is tested, this is tested using arustc
wrapper.