Skip to content

Commit 74fdb5c

Browse files
committed
patch away --error-format and --json so that errors are rendered properly
1 parent 119bf4d commit 74fdb5c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cargo-miri/bin.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,16 +588,32 @@ fn phase_cargo_runner(binary: &str, binary_args: env::Args) {
588588
}
589589

590590
let mut cmd = miri();
591-
// Forward rustc arguments. We need to patch "--extern" filenames because
592-
// we forced a check-only build without cargo knowing about that: replace `.rlib` suffix by `.rmeta`.
591+
// Forward rustc arguments.
592+
// We need to patch "--extern" filenames because we forced a check-only
593+
// build without cargo knowing about that: replace `.rlib` suffix by
594+
// `.rmeta`.
595+
// We also need to remove `--error-format` as cargo specifies that to be JSON,
596+
// but when we run here, cargo does not interpret the JSON any more. `--json`
597+
// then also nees to be dropped.
593598
let mut args = info.args.into_iter();
594599
let extern_flag = "--extern";
600+
let error_format_flag = "--error-format";
601+
let json_flag = "--json";
595602
while let Some(arg) = args.next() {
596603
if arg == extern_flag {
604+
// `--extern` is always passed as a separate argument by cargo.
597605
let next_arg = args.next().expect("`--extern` should be followed by a filename");
598606
let next_arg = next_arg.strip_suffix(".rlib").expect("all extern filenames should end in `.rlib`");
599607
cmd.arg(extern_flag);
600608
cmd.arg(format!("{}.rmeta", next_arg));
609+
} else if arg.starts_with(error_format_flag) {
610+
let suffix = &arg[error_format_flag.len()..];
611+
assert!(suffix.starts_with('='));
612+
// Drop this argument.
613+
} else if arg.starts_with(json_flag) {
614+
let suffix = &arg[json_flag.len()..];
615+
assert!(suffix.starts_with('='));
616+
// Drop this argument.
601617
} else {
602618
cmd.arg(arg);
603619
}

0 commit comments

Comments
 (0)