mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
fix: Make auto-fix note work with clippy
This commit is contained in:
parent
a56fedcea4
commit
33c32088fa
@ -54,6 +54,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
|
|||||||
use std::fmt::Write as _;
|
use std::fmt::Write as _;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::marker;
|
use std::marker;
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread::{self, Scope};
|
use std::thread::{self, Scope};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -799,7 +800,11 @@ impl<'cfg> DrainState<'cfg> {
|
|||||||
self.tokens.extend(rustc_tokens);
|
self.tokens.extend(rustc_tokens);
|
||||||
}
|
}
|
||||||
self.to_send_clients.remove(&id);
|
self.to_send_clients.remove(&id);
|
||||||
self.report_warning_count(cx.bcx.config, id);
|
self.report_warning_count(
|
||||||
|
cx.bcx.config,
|
||||||
|
id,
|
||||||
|
&cx.bcx.rustc().workspace_wrapper,
|
||||||
|
);
|
||||||
self.active.remove(&id).unwrap()
|
self.active.remove(&id).unwrap()
|
||||||
}
|
}
|
||||||
// ... otherwise if it hasn't finished we leave it
|
// ... otherwise if it hasn't finished we leave it
|
||||||
@ -1243,7 +1248,12 @@ impl<'cfg> DrainState<'cfg> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Displays a final report of the warnings emitted by a particular job.
|
/// Displays a final report of the warnings emitted by a particular job.
|
||||||
fn report_warning_count(&mut self, config: &Config, id: JobId) {
|
fn report_warning_count(
|
||||||
|
&mut self,
|
||||||
|
config: &Config,
|
||||||
|
id: JobId,
|
||||||
|
rustc_workspace_wrapper: &Option<PathBuf>,
|
||||||
|
) {
|
||||||
let count = match self.warning_count.remove(&id) {
|
let count = match self.warning_count.remove(&id) {
|
||||||
// An error could add an entry for a `Unit`
|
// An error could add an entry for a `Unit`
|
||||||
// with 0 warnings but having fixable
|
// with 0 warnings but having fixable
|
||||||
@ -1276,7 +1286,16 @@ impl<'cfg> DrainState<'cfg> {
|
|||||||
if let FixableWarnings::Positive(fixable) = count.fixable {
|
if let FixableWarnings::Positive(fixable) = count.fixable {
|
||||||
// `cargo fix` doesnt have an option for custom builds
|
// `cargo fix` doesnt have an option for custom builds
|
||||||
if !unit.target.is_custom_build() {
|
if !unit.target.is_custom_build() {
|
||||||
let mut command = {
|
// 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();
|
let named = unit.target.description_named();
|
||||||
// if its a lib we need to add the package to fix
|
// if its a lib we need to add the package to fix
|
||||||
if unit.target.is_lib() {
|
if unit.target.is_lib() {
|
||||||
@ -1288,7 +1307,7 @@ impl<'cfg> DrainState<'cfg> {
|
|||||||
if unit.mode.is_rustc_test()
|
if unit.mode.is_rustc_test()
|
||||||
&& !(unit.target.is_test() || unit.target.is_bench())
|
&& !(unit.target.is_test() || unit.target.is_bench())
|
||||||
{
|
{
|
||||||
command.push_str(" --tests");
|
args.push_str(" --tests");
|
||||||
}
|
}
|
||||||
let mut suggestions = format!("{} suggestion", fixable);
|
let mut suggestions = format!("{} suggestion", fixable);
|
||||||
if fixable > 1 {
|
if fixable > 1 {
|
||||||
@ -1296,8 +1315,7 @@ impl<'cfg> DrainState<'cfg> {
|
|||||||
}
|
}
|
||||||
drop(write!(
|
drop(write!(
|
||||||
message,
|
message,
|
||||||
" (run `cargo fix --{}` to apply {})",
|
" (run `{command} --{args}` to apply {suggestions})"
|
||||||
command, suggestions
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1447,3 +1447,50 @@ fn check_fixable_mixed() {
|
|||||||
.with_stderr_contains("[..] (run `cargo fix --bench \"bench\"` to apply 1 suggestion)")
|
.with_stderr_contains("[..] (run `cargo fix --bench \"bench\"` to apply 1 suggestion)")
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn check_fixable_warning_for_clippy() {
|
||||||
|
// A wrapper around `rustc` instead of calling `clippy`
|
||||||
|
let clippy_driver = project()
|
||||||
|
.at(cargo_test_support::paths::global_root().join("clippy-driver"))
|
||||||
|
.file("Cargo.toml", &basic_manifest("clippy-driver", "0.0.1"))
|
||||||
|
.file(
|
||||||
|
"src/main.rs",
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
let mut args = std::env::args_os();
|
||||||
|
let _me = args.next().unwrap();
|
||||||
|
let rustc = args.next().unwrap();
|
||||||
|
let status = std::process::Command::new(rustc).args(args).status().unwrap();
|
||||||
|
std::process::exit(status.code().unwrap_or(1));
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
clippy_driver.cargo("build").run();
|
||||||
|
|
||||||
|
let foo = project()
|
||||||
|
.file(
|
||||||
|
"Cargo.toml",
|
||||||
|
r#"
|
||||||
|
[package]
|
||||||
|
name = "foo"
|
||||||
|
version = "0.0.1"
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
// We don't want to show a warning that is `clippy`
|
||||||
|
// specific since we are using a `rustc` wrapper
|
||||||
|
// inplace of `clippy`
|
||||||
|
.file("src/lib.rs", "use std::io;")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
foo.cargo("check")
|
||||||
|
// We can't use `clippy` so we use a `rustc` workspace wrapper instead
|
||||||
|
.env(
|
||||||
|
"RUSTC_WORKSPACE_WRAPPER",
|
||||||
|
clippy_driver.bin("clippy-driver"),
|
||||||
|
)
|
||||||
|
.masquerade_as_nightly_cargo(&["auto-fix note"])
|
||||||
|
.with_stderr_contains("[..] (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion)")
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user