Skip to content

Commit 88af506

Browse files
committed
cleanup: Remove error-format special-case in cargo fix
`cargo fix` had some special handling to deal with ensuring that the `--error-format=json` flag was passed to rustc. However, cargo was changed in rust-lang#7450 to always pass that flag. This special handling is no longer necessary, so this PR removes it.
1 parent 2ed2dbd commit 88af506

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

src/cargo/ops/fix.rs

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,7 @@ pub fn fix_exec_rustc(config: &Config, lock_addr: &str) -> CargoResult<()> {
381381
args.apply(&mut rustc);
382382

383383
trace!("start rustfixing {:?}", args.file);
384-
let json_error_rustc = {
385-
let mut cmd = rustc.clone();
386-
cmd.arg("--error-format=json");
387-
cmd
388-
};
389-
let fixes = rustfix_crate(&lock_addr, &json_error_rustc, &args.file, &args, config)?;
384+
let fixes = rustfix_crate(&lock_addr, &rustc, &args.file, &args, config)?;
390385

391386
// Ok now we have our final goal of testing out the changes that we applied.
392387
// If these changes went awry and actually started to cause the crate to
@@ -397,8 +392,8 @@ pub fn fix_exec_rustc(config: &Config, lock_addr: &str) -> CargoResult<()> {
397392
// new rustc, and otherwise we capture the output to hide it in the scenario
398393
// that we have to back it all out.
399394
if !fixes.files.is_empty() {
400-
debug!("calling rustc for final verification: {json_error_rustc}");
401-
let output = json_error_rustc.output()?;
395+
debug!("calling rustc for final verification: {rustc}");
396+
let output = rustc.output()?;
402397

403398
if output.status.success() {
404399
for (path, file) in fixes.files.iter() {
@@ -429,7 +424,7 @@ pub fn fix_exec_rustc(config: &Config, lock_addr: &str) -> CargoResult<()> {
429424
}
430425

431426
let krate = {
432-
let mut iter = json_error_rustc.get_args();
427+
let mut iter = rustc.get_args();
433428
let mut krate = None;
434429
while let Some(arg) = iter.next() {
435430
if arg == "--crate-name" {
@@ -446,11 +441,7 @@ pub fn fix_exec_rustc(config: &Config, lock_addr: &str) -> CargoResult<()> {
446441
// - If the fix failed, show the original warnings and suggestions.
447442
// - If `--broken-code`, show the error messages.
448443
// - If the fix succeeded, show any remaining warnings.
449-
for arg in args.format_args {
450-
// Add any json/error format arguments that Cargo wants. This allows
451-
// things like colored output to work correctly.
452-
rustc.arg(arg);
453-
}
444+
//
454445
// Removes `FD_CLOEXEC` set by `jobserver::Client` to pass jobserver
455446
// as environment variables specify.
456447
if let Some(client) = config.jobserver_from_env() {
@@ -799,12 +790,6 @@ struct FixArgs {
799790
other: Vec<OsString>,
800791
/// Path to the `rustc` executable.
801792
rustc: PathBuf,
802-
/// Console output flags (`--error-format`, `--json`, etc.).
803-
///
804-
/// The normal fix procedure always uses `--json`, so it overrides what
805-
/// Cargo normally passes when applying fixes. When displaying warnings or
806-
/// errors, it will use these flags.
807-
format_args: Vec<String>,
808793
}
809794

810795
impl FixArgs {
@@ -822,7 +807,6 @@ impl FixArgs {
822807
let mut file = None;
823808
let mut enabled_edition = None;
824809
let mut other = Vec::new();
825-
let mut format_args = Vec::new();
826810

827811
let mut handle_arg = |arg: OsString| -> CargoResult<()> {
828812
let path = PathBuf::from(arg);
@@ -835,12 +819,6 @@ impl FixArgs {
835819
enabled_edition = Some(edition.parse()?);
836820
return Ok(());
837821
}
838-
if s.starts_with("--error-format=") || s.starts_with("--json=") {
839-
// Cargo may add error-format in some cases, but `cargo
840-
// fix` wants to add its own.
841-
format_args.push(s.to_string());
842-
return Ok(());
843-
}
844822
}
845823
other.push(path.into());
846824
Ok(())
@@ -890,7 +868,6 @@ impl FixArgs {
890868
enabled_edition,
891869
other,
892870
rustc,
893-
format_args,
894871
})
895872
}
896873

0 commit comments

Comments
 (0)