Skip to content

Suggest cargo clippy --fix with trailing lint groups/levels arguments #11671

Open
@weihanglo

Description

@weihanglo

Problem

After running cargo clippy -- -W clippy::doc_markdown, Cargo suggests

warning: `cargo` (lib) generated 83 warnings (run `cargo clippy --fix --lib -p cargo` to apply 79 suggestions)

To make the suggestion work, I believe trailing cli arguments should be added. That is

cargo clippy --fix --lib -p cargo -- -W clippy::doc_markdown`.

Steps

  1. Switch the toolchain to the version mentioned below.
  2. Checkout rust-lang/cargo to 0b2c38f.
  3. Run cargo clippy -- -W clippy::doc_markdown.
  4. Copy the suggested commmand and run it.
  5. Nothing happen. Nothing fixed.

Possible Solution(s)

Suggest trailing varargs here? Not sure if it could be a bit overkill though.

if let FixableWarnings::Positive(fixable) = count.fixable {
// `cargo fix` doesnt have an option for custom builds
if !unit.target.is_custom_build() {
// To make sure the correct command is shown for `clippy` we
// 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 mut args = {
let named = unit.target.description_named();
// if its a lib we need to add the package to fix
if unit.target.is_lib() {
format!("{} -p {}", named, unit.pkg.name())
} else {
named
}
};
if unit.mode.is_rustc_test()
&& !(unit.target.is_test() || unit.target.is_bench())
{
args.push_str(" --tests");
}
let mut suggestions = format!("{} suggestion", fixable);
if fixable > 1 {
suggestions.push_str("s")
}
drop(write!(
message,
" (run `{command} --{args}` to apply {suggestions})"
))
}

Notes

cc #11605 and @Muscraft

Version

cargo 1.69.0-nightly (e84a7928d 2023-01-31)
release: 1.69.0-nightly
commit-hash: e84a7928d93a31f284b497c214a2ece69b4d7719
commit-date: 2023-01-31
host: aarch64-apple-darwin
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.79.1 (sys:0.4.59+curl-7.86.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 12.6.3 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.C-bugCategory: bugCommand-clippyS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions