From 4e786ef0e52e251c7cd740f7835a02783d522e2a Mon Sep 17 00:00:00 2001 From: Alejandra Gonzalez Date: Wed, 18 Feb 2026 18:42:39 +0100 Subject: [PATCH] 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 --- src/cargo/core/compiler/job_queue/mod.rs | 29 +++++++++++++++++++----- tests/testsuite/check.rs | 2 +- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/cargo/core/compiler/job_queue/mod.rs b/src/cargo/core/compiler/job_queue/mod.rs index 3a5c150bf..45da8b351 100644 --- a/src/cargo/core/compiler/job_queue/mod.rs +++ b/src/cargo/core/compiler/job_queue/mod.rs @@ -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() + } ); } } diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index daaa1f83a..7d22423be 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -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();