-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Add cargo_cfg_target_family_multivalued FCW
#147545
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
base: master
Are you sure you want to change the base?
Conversation
| /// | ||
| /// [CARGO_CFG_TARGET_FAMILY]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#:~:text=CARGO_CFG_TARGET_FAMILY | ||
| /// [cfg-target_family]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_family | ||
| CARGO_CFG_TARGET_FAMILY_MULTIVALUED, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about the name? cargo_cfg_target_family_multivalued is kinda long, but I felt that shortening it risked loosing meaning. _multivalued isn't the best descriptor though, perhaps _direct_comparison would be better?
| struct ReplaceWithSplitAny { | ||
| #[suggestion_part(code = "!")] | ||
| negate: Option<Span>, | ||
| #[suggestion_part(code = ".split(',').any(|x| x == ")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could suggest .contains("unix") instead, that'd work as well. I felt .split(',').any(|x| x == "unix") was more principled, but I'd be fine with either.
| Warn, | ||
| "comparing `CARGO_CFG_TARGET_FAMILY` env var with a single value", | ||
| @future_incompatible = FutureIncompatibleInfo { | ||
| reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure if this is the intended use of a FCW? I would like it to trigger in dependents some day, but there wasn't precedent for using FutureReleaseSemanticsChange anywhere.
|
Just to summarize, I think the main questions for lang is:
|
cargo_cfg_target_family_multivalued lintcargo_cfg_target_family_multivalued FCW
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