Skip to content

Commit c2e50aa

Browse files
committed
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.
1 parent 39d51c2 commit c2e50aa

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/cargo/core/compiler/job_queue/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,9 +1105,18 @@ impl<'gctx> DrainState<'gctx> {
11051105
if fixable > 1 {
11061106
suggestions.push_str("s")
11071107
}
1108+
11081109
let _ = write!(
11091110
message,
1110-
" (run `{command} --{args}` to apply {suggestions})"
1111+
" (run `{command} --{args}{}` to apply {suggestions})",
1112+
if let Ok(cli_lints) = gctx.get_env("CLIPPY_ARGS") {
1113+
// Clippy can take lints through the CLI, each lint flag is separated by "__CLIPPY_HACKER__".
1114+
let cli_lints = cli_lints.replace("__CLIPPY_HACKERY__", " ");
1115+
let cli_lints = cli_lints.trim_ascii_end(); // Remove that last space left by __CLIPPY_HACKERY__
1116+
format!(" -- {cli_lints}")
1117+
} else {
1118+
"".to_owned()
1119+
}
11111120
);
11121121
}
11131122
}

tests/testsuite/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ fn check_fixable_warning_for_clippy() {
15581558
.env("CLIPPY_ARGS", "-Wclippy::pedantic__CLIPPY_HACKERY__-Aclippy::allow_attributes__CLIPPY_HACKERY__") // Set -Wclippy::pedantic
15591559
.with_stderr_data(str![[r#"
15601560
...
1561-
[WARNING] `foo` (lib) generated 1 warning (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion)
1561+
[WARNING] `foo` (lib) generated 1 warning (run `cargo clippy --fix --lib -p foo -- -Wclippy::pedantic -Aclippy::allow_attributes` to apply 1 suggestion)
15621562
...
15631563
"#]])
15641564
.run();

0 commit comments

Comments
 (0)