mirror of
https://github.com/rust-lang/cargo.git
synced 2026-03-12 19:40:13 +00:00
fix(job_queue): Handle Clippy CLI arguments in fix message
fixes #16637 Clippy lints can be enabled via the command line via `cargo clippy -- -Wclippy::lint`, and these need to be included in the `cargo fix` command for the emitting lints to actually be fixed. Thus, add them to the "run `..` to apply .. suggestions" message. Only suggest when running from clippy-driver
This commit is contained in:
parent
b0c383914a
commit
4e786ef0e5
@ -116,11 +116,11 @@ mod job_state;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fmt::Write as _;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use std::thread::{self, Scope};
|
||||
use std::time::Duration;
|
||||
use std::{env, io};
|
||||
|
||||
use anyhow::{Context as _, format_err};
|
||||
use jobserver::{Acquired, HelperThread};
|
||||
@ -1089,11 +1089,15 @@ impl<'gctx> DrainState<'gctx> {
|
||||
// check if `RUSTC_WORKSPACE_WRAPPER` is set and pointing towards
|
||||
// `clippy-driver`.
|
||||
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",
|
||||
let is_clippy = rustc_workspace_wrapper.as_ref().and_then(|x| x.file_stem())
|
||||
== Some(clippy);
|
||||
|
||||
let command = if is_clippy {
|
||||
"cargo clippy --fix"
|
||||
} else {
|
||||
"cargo fix"
|
||||
};
|
||||
|
||||
let mut args =
|
||||
format!("{} -p {}", unit.target.description_named(), unit.pkg.name());
|
||||
if unit.mode.is_rustc_test()
|
||||
@ -1105,9 +1109,22 @@ impl<'gctx> DrainState<'gctx> {
|
||||
if fixable > 1 {
|
||||
suggestions.push_str("s")
|
||||
}
|
||||
|
||||
#[expect(clippy::disallowed_methods, reason = "consistency with clippy")]
|
||||
let _ = write!(
|
||||
message,
|
||||
" (run `{command} --{args}` to apply {suggestions})"
|
||||
" (run `{command} --{args}{}` to apply {suggestions})",
|
||||
if let Some(cli_lints_os) = env::var_os("CLIPPY_ARGS")
|
||||
&& let Ok(cli_lints) = cli_lints_os.into_string()
|
||||
&& is_clippy
|
||||
{
|
||||
// Clippy can take lints through the CLI, each lint flag is separated by "__CLIPPY_HACKERY__".
|
||||
let cli_lints = cli_lints.replace("__CLIPPY_HACKERY__", " ");
|
||||
let cli_lints = cli_lints.trim_ascii_end(); // Remove that last space left by __CLIPPY_HACKERY__
|
||||
format!(" -- {cli_lints}")
|
||||
} else {
|
||||
"".to_owned()
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1558,7 +1558,7 @@ fn check_fixable_warning_for_clippy() {
|
||||
.env("CLIPPY_ARGS", "-Wclippy::pedantic__CLIPPY_HACKERY__-Aclippy::allow_attributes__CLIPPY_HACKERY__") // Set -Wclippy::pedantic
|
||||
.with_stderr_data(str![[r#"
|
||||
...
|
||||
[WARNING] `foo` (lib) generated 1 warning (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion)
|
||||
[WARNING] `foo` (lib) generated 1 warning (run `cargo clippy --fix --lib -p foo -- -Wclippy::pedantic -Aclippy::allow_attributes` to apply 1 suggestion)
|
||||
...
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user