]> git.proxmox.com Git - cargo.git/commitdiff
Auto merge of #7748 - ehuss:fix-config-env-var-prefix, r=alexcrichton
authorbors <bors@rust-lang.org>
Mon, 6 Jan 2020 15:20:09 +0000 (15:20 +0000)
committerbors <bors@rust-lang.org>
Mon, 6 Jan 2020 15:20:09 +0000 (15:20 +0000)
Fix config env vars that are prefix of another with underscore.

This fixes the CARGO_BUILD_TARGET_DIR and CARGO_PROFILE_DEV_DEBUG_ASSERTIONS environment variables.  Hopefully the big comment explains everything, but to review:

`deserialize_option` does not know the type of the value it is about to deserialize.  The type could be a struct, in which case it needs to check if `CARGO_FOO_BAR_*` environment variables are set. However, when deserializing something like `build.target`, this prefix check will incorrectly match `CARGO_BUILD_TARGET_DIR` which happens to be a prefix of `CARGO_BUILD_TARGET_*`.  It attempts to call `visit_some` which fails if `CARGO_BUILD_TARGET` is not set.

The solution here is to detect scenarios where one field is a prefix of another, and skip the environment prefix check (by setting `Deserializer::env_prefix_ok` appropriately).  This means we cannot have `Option<SomeStruct>` be a prefix of another field with an underscore.  I think that's fine, and we should try to probably avoid these kinds a prefixes anyways.

Closes #7253.


Trivial merge