-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Add cargo_cfg_target_family_multivalued
lint
#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.
Add
cargo_cfg_target_family_multivalued
which detects simple comparisons like==
ormatch
on theCARGO_CFG_TARGET_FAMILY
environment variable. These are wrong, sinceCARGO_CFG_TARGET_FAMILY
is multi-valued (currently only onwasm32-unknown-emscripten
andwasm32-wali-linux-musl
, so admittedly pretty rare).This should unblock at some point adding
#[cfg(target_family = "darwin")]
, which in turns unblocks #100343.There exist other multi-valued cfgs such as
CARGO_CFG_TARGET_HAS_ATOMIC
orCARGO_CFG_TARGET_HAS_ATOMIC
, 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