Fix -Zfeatures=itarget with certain host dependencies #8048
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.
In some cases,
-Zfeatures=itarget
can panic because an entry is missing in the activation map. This happens because the way "for_host" was tracked when building the activation map. Previously "for_host" was only set when-Zfeatures=host_dep
was specified. However, if you don't specifyhost_dep
, then "for_host" was always false.This is a problem because
itarget
needs to also be able to detect if something is enabled for the host or target. If you have a proc-macro ("for_host"), and it has a dependency with a[target]
specification that matched the host, then the activation map would fail to include it (because the "for_host" flag was not "sticky" and didn't get passed down).The solution is to always carry the "for_host" setting around while building the activation map. Only when inserting a feature into the map will it check if
opts.decouple_host_deps
is set. This allows it to handle the "for_host" setting correctly, even if thehost_dep
option isn't enabled.This was discovered at #7914 (comment) where a dependency on
hashbrown
would fail if you pass--target something_not_unix
because it has a unix-only dependency forlibc
.(Sorry, long-winded explanation. Please ask if that is confusing.)