docs: note env var influence on temp_dir and env_clear on Windows

* docs: explicitly list env vars checked by temp_dir on Windows

On Windows, temp_dir() internally calls GetTempPath2/GetTempPath which
checks TMP, TEMP, USERPROFILE environment variables in order. This
information was previously only available by following links to Microsoft
docs. Making it explicit in Rust's own documentation improves
discoverability.

Addresses #125439.
* docs: note env var influence on temp_dir and env_clear on Windows

On Windows, nv::temp_dir() internally calls GetTempPath2/GetTempPath,
which checks TMP, TEMP, and USERPROFILE in order. Document this
lookup order directly in the 	emp_dir docs rather than requiring users
to follow the link to Microsoft documentation.

Also add a note on Command::env_clear explaining that clearing the
environment affects the child process's 	emp_dir(), not the parent's.

Closes #125439.
* docs: drop Windows env_clear temp_dir note
This commit is contained in:
shri-prakhar
2026-02-28 16:29:48 +00:00
parent 0028f344ce
commit 220295beef
+11
View File
@@ -670,6 +670,17 @@ pub fn home_dir() -> Option<PathBuf> {
///
/// On Windows, the behavior is equivalent to that of [`GetTempPath2`][GetTempPath2] /
/// [`GetTempPath`][GetTempPath], which this function uses internally.
/// Specifically, for non-SYSTEM processes, the function checks for the
/// following environment variables in order and returns the first path found:
///
/// 1. The path specified by the `TMP` environment variable.
/// 2. The path specified by the `TEMP` environment variable.
/// 3. The path specified by the `USERPROFILE` environment variable.
/// 4. The Windows directory.
///
/// When called from a process running as SYSTEM,
/// [`GetTempPath2`][GetTempPath2] returns `C:\Windows\SystemTemp`
/// regardless of environment variables.
///
/// Note that, this [may change in the future][changes].
///