Improvements for resolving the value of the env!
macro
#20554
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First issue:
Currently
cargo_config_env
assumes thatcargo config
always serializes each entry in theenv
table to an object, but it is valid to use just a string for the value in theenv
table and this is converted to a string in the JSON:The fix for this is to handle JSON strings as well as objects.
Second issue:
Currently the only values available to the
env!
macro are those set in theenv
table of the Cargo configuration file (plus a few other hard coded values). This makes it difficult to simulate having environment variables set (e.g., to match a CI system) without either modifying the current project's configuration (which is usually checked-in) or the user's configuration (which is shared between projects).This change makes the values set in the
cargo.extraEnv
configuration option available via theenv!
macro when loading a project via Cargo manifests. This provides a straightforward way for users to set custom values forenv!
and for those values to be consistent between language services andcargo check
.Note that this feature respects the
force
option in theenv
table, so it will only overwrite the values fromextraEnv
ifforce
is set to true.Fixes #13004
Partial fix for #17593 (changes
env!
but notinclude!
)