diff --git a/src/cargo/ops/fix.rs b/src/cargo/ops/fix.rs index 9d721b71759..db903d7e363 100644 --- a/src/cargo/ops/fix.rs +++ b/src/cargo/ops/fix.rs @@ -346,7 +346,8 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult { let workspace_rustc = std::env::var("RUSTC_WORKSPACE_WRAPPER") .map(PathBuf::from) .ok(); - let rustc = ProcessBuilder::new(&args.rustc).wrapped(workspace_rustc.as_ref()); + let mut rustc = ProcessBuilder::new(&args.rustc).wrapped(workspace_rustc.as_ref()); + rustc.env_remove(FIX_ENV); trace!("start rustfixing {:?}", args.file); let fixes = rustfix_crate(&lock_addr, &rustc, &args.file, &args, config)?; diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index a1a72971b8a..b5f06755526 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -1684,3 +1684,52 @@ fn abnormal_exit() { .with_stderr_contains("Original diagnostics will follow.") .run(); } + +#[cargo_test] +fn fix_with_run_cargo_in_proc_macros() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2018" + + [lib] + proc-macro = true + "#, + ) + .file( + "src/lib.rs", + r#" + use proc_macro::*; + + #[proc_macro] + pub fn foo(_input: TokenStream) -> TokenStream { + let output = std::process::Command::new("cargo") + .args(&["metadata", "--format-version=1"]) + .output() + .unwrap(); + eprintln!("{}", std::str::from_utf8(&output.stderr).unwrap()); + println!("{}", std::str::from_utf8(&output.stdout).unwrap()); + "".parse().unwrap() + } + "#, + ) + .file( + "src/bin/main.rs", + r#" + use foo::foo; + + fn main() { + foo!("bar") + } + "#, + ) + .build(); + p.cargo("fix --allow-no-vcs") + .masquerade_as_nightly_cargo() + .with_stderr_does_not_contain("error: could not find .rs file in rustc args") + .run(); +}