Skip to content
31 changes: 28 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,38 @@ where
{
let mut args = vec!["check".to_owned()];

let mut fix = false;
let mut unstable_options = false;

for arg in old_args.by_ref() {
if arg == "--" {
break;
match arg.as_str() {
"--fix" => {
fix = true;
continue;
},
"--" => break,
// Cover -Zunstable-options and -Z unstable-options
s if s.ends_with("unstable-options") => unstable_options = true,
_ => {},
}

args.push(arg);
}

if fix {
if unstable_options {
args[0] = "fix".to_owned();
} else {
panic!("Usage of `--fix` requires `-Z unstable-options`");
}
}

let path_env = if unstable_options {
"RUSTC_WORKSPACE_WRAPPER"
} else {
"RUSTC_WRAPPER"
};

let clippy_args: String = old_args.map(|arg| format!("{}__CLIPPY_HACKERY__", arg)).collect();

let mut path = std::env::current_exe()
Expand Down Expand Up @@ -96,7 +121,7 @@ where

let exit_status = std::process::Command::new("cargo")
.args(&args)
.env("RUSTC_WRAPPER", path)
.env(path_env, path)
.env("CLIPPY_ARGS", clippy_args)
.envs(target_dir)
.spawn()
Expand Down