Skip to content

Commit 4225c46

Browse files
committed
unset the FIX_ENV when executing the real rustc
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent 216f915 commit 4225c46

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/cargo/ops/fix.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
346346
let workspace_rustc = std::env::var("RUSTC_WORKSPACE_WRAPPER")
347347
.map(PathBuf::from)
348348
.ok();
349-
let rustc = ProcessBuilder::new(&args.rustc).wrapped(workspace_rustc.as_ref());
349+
let mut rustc = ProcessBuilder::new(&args.rustc).wrapped(workspace_rustc.as_ref());
350+
rustc.env_remove(FIX_ENV);
350351

351352
trace!("start rustfixing {:?}", args.file);
352353
let fixes = rustfix_crate(&lock_addr, &rustc, &args.file, &args, config)?;

tests/testsuite/fix.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,3 +1684,52 @@ fn abnormal_exit() {
16841684
.with_stderr_contains("Original diagnostics will follow.")
16851685
.run();
16861686
}
1687+
1688+
#[cargo_test]
1689+
fn fix_with_run_cargo_in_proc_macros() {
1690+
let p = project()
1691+
.file(
1692+
"Cargo.toml",
1693+
r#"
1694+
[package]
1695+
name = "foo"
1696+
version = "0.1.0"
1697+
edition = "2018"
1698+
1699+
[lib]
1700+
proc-macro = true
1701+
"#,
1702+
)
1703+
.file(
1704+
"src/lib.rs",
1705+
r#"
1706+
use proc_macro::*;
1707+
1708+
#[proc_macro]
1709+
pub fn foo(_input: TokenStream) -> TokenStream {
1710+
let output = std::process::Command::new("cargo")
1711+
.args(&["metadata", "--format-version=1"])
1712+
.output()
1713+
.unwrap();
1714+
eprintln!("{}", std::str::from_utf8(&output.stderr).unwrap());
1715+
println!("{}", std::str::from_utf8(&output.stdout).unwrap());
1716+
"".parse().unwrap()
1717+
}
1718+
"#,
1719+
)
1720+
.file(
1721+
"src/bin/main.rs",
1722+
r#"
1723+
use foo::foo;
1724+
1725+
fn main() {
1726+
foo!("bar")
1727+
}
1728+
"#,
1729+
)
1730+
.build();
1731+
p.cargo("fix --allow-no-vcs")
1732+
.masquerade_as_nightly_cargo()
1733+
.with_stderr_does_not_contain("error: could not find .rs file in rustc args")
1734+
.run();
1735+
}

0 commit comments

Comments
 (0)