Add cargo_cfg_target_family_multivalued FCW #147545 
     Open  
   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.    
 
Add
cargo_cfg_target_family_multivaluedlint which detects simple comparisons like==ormatchon theCARGO_CFG_TARGET_FAMILYenvironment variable. These are wrong, sinceCARGO_CFG_TARGET_FAMILYis multi-valued (currently only onwasm32-unknown-emscriptenandwasm32-wali-linux-musl, so admittedly pretty rare).This lint is inherently incomplete, because we can't track a value like this through arbitrary control flow. Regardless, I've found that it works pretty well in practice, from the various repos I took a look at that used
CARGO_CFG_TARGET_FAMILY, I'd guess at least 80% of them would hit this lint.This should unblock at some point adding
#[cfg(target_family = "darwin")]as a replacement for#[cfg(target_vendor = "apple")], which in turns unblocks #100343.There exist other multi-valued cfgs such as
CARGO_CFG_TARGET_HAS_ATOMICorCARGO_CFG_TARGET_FEATURE, but these were very clearly multi-valued from the beginning, and thus doesn't make sense to lint for.This is my first time adding a lint, so beware that I'm a bit unsure if I did things right. Especially unsure if I should feature-gate the lint to start with, or if we should insta-stabilize it? I'm pretty sure it needs a lang FCP though.
r? compiler
CC @thomcc @workingjubilee