Skip to content

Commit

Permalink
patch away --error-format and --json so that errors are rendered prop…
Browse files Browse the repository at this point in the history
…erly
  • Loading branch information
RalfJung committed Sep 9, 2020
1 parent 1f42b4b commit 4acab80
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions cargo-miri/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,16 +585,32 @@ fn phase_cargo_runner(binary: &str, binary_args: env::Args) {
}

let mut cmd = miri();
// Forward rustc arguments. We need to patch "--extern" filenames because
// we forced a check-only build without cargo knowing about that: replace `.rlib` suffix by `.rmeta`.
// Forward rustc arguments.
// We need to patch "--extern" filenames because we forced a check-only
// build without cargo knowing about that: replace `.rlib` suffix by
// `.rmeta`.
// We also need to remove `--error-format` as cargo specifies that to be JSON,
// but when we run here, cargo does not interpret the JSON any more. `--json`
// then also nees to be dropped.
let mut args = info.args.into_iter();
let extern_flag = "--extern";
let error_format_flag = "--error-format";
let json_flag = "--json";
while let Some(arg) = args.next() {
if arg == extern_flag {
// `--extern` is always passed as a separate argument by cargo.
let next_arg = args.next().expect("`--extern` should be followed by a filename");
let next_arg = next_arg.strip_suffix(".rlib").expect("all extern filenames should end in `.rlib`");
cmd.arg(extern_flag);
cmd.arg(format!("{}.rmeta", next_arg));
} else if arg.starts_with(error_format_flag) {
let suffix = &arg[error_format_flag.len()..];
assert!(suffix.starts_with('='));
// Drop this argument.
} else if arg.starts_with(json_flag) {
let suffix = &arg[json_flag.len()..];
assert!(suffix.starts_with('='));
// Drop this argument.
} else {
cmd.arg(arg);
}
Expand Down

0 comments on commit 4acab80

Please sign in to comment.