Skip to content

Commit 4d42e0a

Browse files
committed
patch away --error-format and --json so that errors are rendered properly
1 parent a6cd89f commit 4d42e0a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cargo-miri/bin.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -585,16 +585,32 @@ fn phase_cargo_runner(binary: &str, binary_args: env::Args) {
585585
}
586586

587587
let mut cmd = miri();
588-
// Forward rustc arguments. We need to patch "--extern" filenames because
589-
// we forced a check-only build without cargo knowing about that: replace `.rlib` suffix by `.rmeta`.
588+
// Forward rustc arguments.
589+
// We need to patch "--extern" filenames because we forced a check-only
590+
// build without cargo knowing about that: replace `.rlib` suffix by
591+
// `.rmeta`.
592+
// We also need to remove `--error-format` as cargo specifies that to be JSON,
593+
// but when we run here, cargo does not interpret the JSON any more. `--json`
594+
// then also nees to be dropped.
590595
let mut args = info.args.into_iter();
591596
let extern_flag = "--extern";
597+
let error_format_flag = "--error-format";
598+
let json_flag = "--json";
592599
while let Some(arg) = args.next() {
593600
if arg == extern_flag {
601+
// `--extern` is always passed as a separate argument by cargo.
594602
let next_arg = args.next().expect("`--extern` should be followed by a filename");
595603
let next_arg = next_arg.strip_suffix(".rlib").expect("all extern filenames should end in `.rlib`");
596604
cmd.arg(extern_flag);
597605
cmd.arg(format!("{}.rmeta", next_arg));
606+
} else if arg.starts_with(error_format_flag) {
607+
let suffix = &arg[error_format_flag.len()..];
608+
assert!(suffix.starts_with('='));
609+
// Drop this argument.
610+
} else if arg.starts_with(json_flag) {
611+
let suffix = &arg[json_flag.len()..];
612+
assert!(suffix.starts_with('='));
613+
// Drop this argument.
598614
} else {
599615
cmd.arg(arg);
600616
}

0 commit comments

Comments
 (0)