Repository: rust-lang/cargo (rust)

Issue:
CARGO_RUSTC_CURRENT_DIR is causing forced rebuilds
### Problem

In the cargo repo, there is an environment override setting the `CARGO_RUSTC_CURRENT_DIR` environment variable: https://github.com/rust-lang/cargo/blob/79866e12c663e866a904d713c29745563a64aafa/.cargo/config.toml#L7-L10

This is causing `testsuite` to always be considered dirty on my system. I am getting:

```
FsStatusOutdated(StaleItem(ChangedEnv 
{ var: "CARGO_RUSTC_CURRENT_DIR", 
previous: Some("/Users/eric/Proj/rust/cargo"), 
current: Some("/Users/eric/Proj/rust/cargo/") 
}
```

### Steps

1. Check out rust-lang/cargo
2. `cargo test --test testsuite --no-run`
3. `cargo test --test testsuite --no-run` -- This should build testsuite again.

### Possible Solution(s)

_No response_

### Notes

_No response_

### Version

```text
cargo 1.84.0-nightly (031049782 2024-11-01)
release: 1.84.0-nightly
commit-hash: 0310497822a7a673a330a5dd068b7aaa579a265e
commit-date: 2024-11-01
host: aarch64-apple-darwin
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.7.1 (sys:0.4.74+curl-8.9.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 14.6.1 [64-bit]
```

Pull request description:
Revert "feat: Add `CARGO_RUSTC_CURRENT_DIR`"
### What does this PR try to resolve?

This reverts commit e81d84cc17d7df6a249e60cbc620f25edbe782db.

We decided to not stabilize this in #13644.

### How should we test and review this PR?

### Additional information

This does not fix the underlying issue of #14798



Patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index dddbee956..04f756e93 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -23,7 +23,6 @@ jobs:
       - clippy
       - msrv
       - docs
-      - lint-docs
       - lockfile
       - resolver
       - rustfmt
diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs
index 5d0e2962c..584fc7d07 100644
--- a/src/cargo/core/compiler/mod.rs
+++ b/src/cargo/core/compiler/mod.rs
@@ -717,16 +717,6 @@ fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult
         let tmp = build_runner.files().layout(unit.kind).prepare_tmp()?;
         base.env("CARGO_TARGET_TMPDIR", tmp.display().to_string());
     }
-    if build_runner.bcx.gctx.nightly_features_allowed {
-        // This must come after `build_base_args` (which calls `add_path_args`) so that the `cwd`
-        // is set correctly.
-        base.env(
-            "CARGO_RUSTC_CURRENT_DIR",
-            base.get_cwd()
-                .map(|c| c.display().to_string())
-                .unwrap_or(String::new()),
-        );
-    }
 
     Ok(base)
 }
diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md
index 5dafb7bcb..c47c5d178 100644
--- a/src/doc/src/reference/environment-variables.md
+++ b/src/doc/src/reference/environment-variables.md
@@ -269,7 +269,6 @@ corresponding environment variable is set to the empty string, `""`.
   where integration tests or benchmarks are free to put any data needed by
   the tests/benches. Cargo initially creates this directory but doesn't
   manage its content in any way, this is the responsibility of the test code.
-* `CARGO_RUSTC_CURRENT_DIR` --- This is a path that `rustc` is invoked from **(nightly only)**.
 
 [Cargo target]: cargo-targets.md
 [binaries]: cargo-targets.md#binaries


Test patch:
diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs
index e18497203..9f8649f82 100644
--- a/tests/testsuite/build.rs
+++ b/tests/testsuite/build.rs
@@ -1656,11 +1656,6 @@ fn crate_env_vars() {
 
                     // Verify CARGO_TARGET_TMPDIR isn't set for bins
                     assert!(option_env!("CARGO_TARGET_TMPDIR").is_none());
-
-                    // Verify CARGO_RUSTC_CURRENT_DIR is set for examples
-                    let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
-                    let file_path = workspace_dir.join(file!());
-                    assert!(file_path.exists(), "{}", file_path.display());
                 }
             "#,
         )
@@ -1698,11 +1693,6 @@ fn crate_env_vars() {
                     // Check that CARGO_TARGET_TMPDIR isn't set for lib code
                     assert!(option_env!("CARGO_TARGET_TMPDIR").is_none());
                     env::var("CARGO_TARGET_TMPDIR").unwrap_err();
-
-                    // Verify CARGO_RUSTC_CURRENT_DIR is set for examples
-                    let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
-                    let file_path = workspace_dir.join(file!());
-                    assert!(file_path.exists(), "{}", file_path.display());
                 }
 
                 #[test]
@@ -1711,13 +1701,6 @@ fn crate_env_vars() {
                     assert!(option_env!("CARGO_TARGET_TMPDIR").is_none());
                     env::var("CARGO_TARGET_TMPDIR").unwrap_err();
                 }
-
-                #[test]
-                fn unit_env_cargo_rustc_current_dir() {
-                    let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
-                    let file_path = workspace_dir.join(file!());
-                    assert!(file_path.exists(), "{}", file_path.display());
-                }
             "#,
         )
         .file(
@@ -1734,11 +1717,6 @@ fn crate_env_vars() {
 
                     // Verify CARGO_TARGET_TMPDIR isn't set for examples
                     assert!(option_env!("CARGO_TARGET_TMPDIR").is_none());
-
-                    // Verify CARGO_RUSTC_CURRENT_DIR is set for examples
-                    let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
-                    let file_path = workspace_dir.join(file!());
-                    assert!(file_path.exists(), "{}", file_path.display());
                 }
             "#,
         )
@@ -1749,13 +1727,6 @@ fn crate_env_vars() {
                 fn integration_env_cargo_target_tmpdir() {
                     foo::check_tmpdir(option_env!("CARGO_TARGET_TMPDIR"));
                 }
-
-                #[test]
-                fn integration_env_cargo_rustc_current_dir() {
-                    let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
-                    let file_path = workspace_dir.join(file!());
-                    assert!(file_path.exists(), "{}", file_path.display());
-                }
             "#,
         );
 
@@ -1771,13 +1742,6 @@ fn crate_env_vars() {
                 fn bench_env_cargo_target_tmpdir(_: &mut Bencher) {
                     foo::check_tmpdir(option_env!("CARGO_TARGET_TMPDIR"));
                 }
-
-                #[test]
-                fn bench_env_cargo_rustc_current_dir() {
-                    let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
-                    let file_path = workspace_dir.join(file!());
-                    assert!(file_path.exists(), "{}", file_path.display());
-                }
             "#,
         )
         .build()
@@ -1786,9 +1750,7 @@ fn crate_env_vars() {
     };
 
     println!("build");
-    p.cargo("build -v")
-        .masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
-        .run();
+    p.cargo("build -v").run();
 
     println!("bin");
     p.process(&p.bin("foo-bar"))
@@ -1799,229 +1761,15 @@ fn crate_env_vars() {
         .run();
 
     println!("example");
-    p.cargo("run --example ex-env-vars -v")
-        .masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
-        .run();
+    p.cargo("run --example ex-env-vars -v").run();
 
     println!("test");
-    p.cargo("test -v")
-        .masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
-        .run();
+    p.cargo("test -v").run();
 
     if is_nightly() {
         println!("bench");
-        p.cargo("bench -v")
-            .masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
-            .run();
-    }
-}
-
-#[cargo_test]
-fn cargo_rustc_current_dir_foreign_workspace_dep() {
-    let foo = project()
-        .file(
-            "Cargo.toml",
-            r#"
-            [workspace]
-
-            [package]
-            name = "foo"
-            version = "0.0.1"
-            edition = "2015"
-            authors = []
-
-            [dependencies]
-            baz.path = "../baz"
-            baz_member.path = "../baz/baz_member"
-            "#,
-        )
-        .file("src/lib.rs", "")
-        .build();
-    let _baz = project()
-        .at("baz")
-        .file(
-            "Cargo.toml",
-            r#"
-            [workspace]
-            members = ["baz_member"]
-
-            [package]
-            name = "baz"
-            version = "0.1.0"
-            edition = "2015"
-            "#,
-        )
-        .file("src/lib.rs", "")
-        .file(
-            "tests/env.rs",
-            r#"
-            use std::path::Path;
-
-            #[test]
-            fn baz_env() {
-                let workspace_dir = Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
-                let manifest_dir = Path::new(option_env!("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
-                let manifest_path = Path::new(option_env!("CARGO_MANIFEST_PATH").expect("CARGO_MANIFEST_PATH"));
-                let current_dir = std::env::current_dir().expect("current_dir");
-                let file_path = workspace_dir.join(file!());
-                assert!(file_path.exists(), "{}", file_path.display());
-                let workspace_dir = std::fs::canonicalize(current_dir.join(workspace_dir)).expect("CARGO_RUSTC_CURRENT_DIR");
-                let manifest_path = std::fs::canonicalize(current_dir.join(manifest_dir.clone()).join("Cargo.toml")).expect("CARGO_MANIFEST_PATH");
-                let manifest_dir = std::fs::canonicalize(current_dir.join(manifest_dir)).expect("CARGO_MANIFEST_DIR");
-                assert_eq!(workspace_dir, manifest_dir.clone());
-                assert_eq!(manifest_dir.join("Cargo.toml"), manifest_path);
-            }
-        "#,
-        )
-        .file(
-            "baz_member/Cargo.toml",
-            r#"
-            [package]
-            name = "baz_member"
-            version = "0.1.0"
-            edition = "2015"
-            authors = []
-            "#,
-        )
-        .file("baz_member/src/lib.rs", "")
-        .file(
-            "baz_member/tests/env.rs",
-            r#"
-            use std::path::Path;
-
-            #[test]
-            fn baz_member_env() {
-                let workspace_dir = Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
-                let file_path = workspace_dir.join(file!());
-                assert!(file_path.exists(), "{}", file_path.display());
-            }
-        "#,
-        )
-        .build();
-
-    // Verify it works from a different workspace
-    foo.cargo("test -p baz")
-        .masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
-        .with_stdout_data(str![[r#"
-
-running 0 tests
-
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
-
-
-running 1 test
-test baz_env ... ok
-
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
-
-
-running 0 tests
-
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
-
-
-"#]])
-        .run();
-    foo.cargo("test -p baz_member")
-        .masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
-        .with_stdout_data(str![[r#"
-
-running 0 tests
-
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
-
-
-running 1 test
-test baz_member_env ... ok
-
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
-
-
-running 0 tests
-
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
-
-
-"#]])
-        .run();
-}
-
-#[cargo_test]
-fn cargo_rustc_current_dir_non_local_dep() {
-    Package::new("bar", "0.1.0")
-        .file(
-            "tests/bar_env.rs",
-            r#"
-            use std::path::Path;
-
-            #[test]
-            fn bar_env() {
-                let workspace_dir = Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
-                let manifest_dir = Path::new(option_env!("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
-                let manifest_path = Path::new(option_env!("CARGO_MANIFEST_PATH").expect("CARGO_MANIFEST_PATH"));
-                let current_dir = std::env::current_dir().expect("current_dir");
-                let file_path = workspace_dir.join(file!());
-                assert!(file_path.exists(), "{}", file_path.display());
-                let workspace_dir = std::fs::canonicalize(current_dir.join(workspace_dir)).expect("CARGO_RUSTC_CURRENT_DIR");
-                let manifest_path = std::fs::canonicalize(current_dir.join(manifest_dir.clone()).join("Cargo.toml")).expect("CARGO_MANIFEST_PATH");
-                let manifest_dir = std::fs::canonicalize(current_dir.join(manifest_dir)).expect("CARGO_MANIFEST_DIR");
-                assert_eq!(workspace_dir, manifest_dir.clone());
-                assert_eq!(manifest_dir.join("Cargo.toml"), manifest_path);
-            }
-        "#,
-        )
-        .publish();
-
-    let p = project()
-        .file("src/lib.rs", "")
-        .file(
-            "Cargo.toml",
-            r#"
-                [package]
-                name = "foo"
-                version = "0.0.1"
-                edition = "2015"
-
-                [dependencies]
-                bar = "0.1.0"
-            "#,
-        )
-        .build();
-
-    p.cargo("test -p bar")
-        .masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
-        .with_stdout_data(str![[r#"
-
-running 1 test
-test bar_env ... ok
-
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
-
-
-"#]])
-        .run();
-}
-
-#[cargo_test]
-fn cargo_rustc_current_dir_is_not_stable() {
-    if is_nightly() {
-        return;
+        p.cargo("bench -v").run();
     }
-    let p = project()
-        .file(
-            "tests/env.rs",
-            r#"
-                use std::path::Path;
-
-                #[test]
-                fn env() {
-                    assert_eq!(option_env!("CARGO_RUSTC_CURRENT_DIR"), None);
-                }
-            "#,
-        )
-        .build();
-
-    p.cargo("test").run();
 }
 
 #[cargo_test]