From 4225c462978e72d400216b11dd008d1a27decc9d Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Sat, 21 Aug 2021 23:48:49 +0800 Subject: [PATCH 1/2] unset the FIX_ENV when executing the real rustc Signed-off-by: hi-rustin --- src/cargo/ops/fix.rs | 3 ++- tests/testsuite/fix.rs | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) 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..7e20fdd3f25 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(); +} From 4c11002b9d0547d50922073142c42e58d54c6128 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Sat, 21 Aug 2021 23:54:59 +0800 Subject: [PATCH 2/2] Better fmt for file body Signed-off-by: hi-rustin --- tests/testsuite/fix.rs | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index 7e20fdd3f25..b5f06755526 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -1691,41 +1691,41 @@ fn fix_with_run_cargo_in_proc_macros() { .file( "Cargo.toml", r#" - [package] - name = "foo" - version = "0.1.0" - edition = "2018" + [package] + name = "foo" + version = "0.1.0" + edition = "2018" - [lib] - proc-macro = true - "#, + [lib] + proc-macro = true + "#, ) .file( "src/lib.rs", r#" - use proc_macro::*; + 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() - } - "#, + #[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; + use foo::foo; - fn main() { - foo!("bar") - } - "#, + fn main() { + foo!("bar") + } + "#, ) .build(); p.cargo("fix --allow-no-vcs")