Skip to content

Treat empty environment variables as unset #4422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Treat empty environment variables as unset #4422

wants to merge 1 commit into from

Conversation

djc
Copy link
Contributor

@djc djc commented Jul 22, 2025

Fixes #4419.

Copy link
Member

@rami3l rami3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure if this is the optimal approach... at least it isn't aware of the existence of non_empty_env_var() as @FranciscoTGouveia has noticed in FranciscoTGouveia@43f8115.

It might indeed be helpful to override the env var fetching behavior in all places, but some sort of merging would be better for future maintenance, and some more investigation/refactoring might be required to change something so global and fundamental in rustup's current behavior. As such, I am hesitant to merge this PR as-is.

@djc
Copy link
Contributor Author

djc commented Jul 22, 2025

I did indeed fail to notice/forgot about the existence of non_empty_env_var(), but I strongly feel that it is better to try to tackle this issue once and for all compared to finding out later we have similar issues with other environment variables. We could try to audit whether this makes sense everywhere, but I think using an empty value to unset values is pretty common usage.

@rami3l
Copy link
Member

rami3l commented Jul 22, 2025

I did indeed fail to notice/forgot about the existence of non_empty_env_var(), but I strongly feel that it is better to try to tackle this issue once and for all compared to finding out later we have similar issues with other environment variables. We could try to audit whether this makes sense everywhere, but I think using an empty value to unset values is pretty common usage.

@djc You are probably right; but before reaching the conclusion I'd like to take some time to further investigate into the use cases of non_empty_env_var() across the repo; maybe your fix has subsumed them all?

@rami3l
Copy link
Member

rami3l commented Jul 24, 2025

@djc Sorry for the long wait, but here is what I have found after my investigation:

non_empty_env_var() has only been used four times in this repo:

  1. RUSTUP_TOOLCHAIN for the active toolchain override
  2. RUSTUP_DIST_SERVER for the distro server override
  3. RUSTUP_DIST_ROOT for the legacy distro server override
  4. RUSTUP_VERSION for overriding the "latest" version in self-updates

... and the current env vars being used in this repo can go to several categories:

  1. URI or FS overrides, e.g. RUSTUP_DIST_ROOT. I don't think this new behavior will be harmful in this case nor should it cause common breakages.
  2. Enumerations, e.g. RUSTUP_TERM_COLOR. Same reasoning as above.
  3. Integers and booleans, e.g. RUSTUP_IO_THREADS, RUSTUP_RECURSION_COUNT, NO_COLOR. Often we won't want to set these variables to empty, so the current change sounds acceptable.
  4. External env vars, including lib (Windows), DYLD_FALLBACK_LIBRARY_PATH (Mac), CARGO, PATH, MANPATH, HOME, SHELL, ZDOTDIR, XDG_CONFIG_HOME. I think this category is the one that needs the most attention, since it's not immediately clear if setting those to empty values has specific semantics.

My current standpoint is that, if we can figure out the 4. above and conclude that it is not violating with what we would like to achieve, we can fully eliminate non_empty_env_var() and close #4424 in favor of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

set RUSTUP_UPDATE_ROOT to empty update failed to parse url
2 participants