You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Nightly-only cfg gating like #[cfg(target_has_atomic)] is confusing #133295
cc @joshtriplett since you r+'d #106856 do you know if there a particular reason why cfg(target_has_atomic) was nightly-gated and not feature-gated? Just asking in case there's a particular reason.
Btw, the current cfg feature gating system assumes that all the values are gated but that doesn't map well for target_has_atomic where only the value-less should be feature gated. We would need to do extend the system to permit feature gating only some values for a cfg name.
changed the title [-]What is `#[cfg(target_has_atomic)]` supposed to do?[/-][+]Nightly-only cfg gating like `#[cfg(target_has_atomic)]` is confusing[/+]on Nov 21, 2024
Knowing which feature gates are active requires evaluating cfg's for the crate root. And the cfg's cargo will see through --print cfg can't be feature gated as there is no source code available at that point. Cargo just runs rustc --print cfg once for each target.
Activity
jieyouxu commentedon Nov 21, 2024
@Nemo157 has another example:
For a given snippet and
rustc --cfg='foo="bar"' --crate-type=lib,On stable 1.82.0 this codegens
On nightly 2024-11-20 this codegens
Further indicating that
target_has_atomichas become active by default, but is this intentional?taiki-e commentedon Nov 21, 2024
This cfg has been added in #106856, and means
any(target_has_atomic = "8", target_has_atomic = "16", target_has_atomic = "32", ...).jieyouxu commentedon Nov 21, 2024
Oh... This is nightly-gated but it is not feature-gated
jieyouxu commentedon Nov 21, 2024
cc @joshtriplett since you r+'d #106856 do you know if there a particular reason why
cfg(target_has_atomic)was nightly-gated and not feature-gated? Just asking in case there's a particular reason.bjorn3 commentedon Nov 21, 2024
All unstable cfg's are nigtly gated and not feature gated.
jieyouxu commentedon Nov 21, 2024
Ah never mind, if that's intended behavior.
Urgau commentedon Nov 21, 2024
That's not true, most unstable cfgs are both nightly gated and feature gated,
rust/compiler/rustc_feature/src/builtin_attrs.rs
Lines 17 to 40 in 717f5df
Btw, the current cfg feature gating system assumes that all the values are gated but that doesn't map well for
target_has_atomicwhere only the value-less should be feature gated. We would need to do extend the system to permit feature gating only some values for a cfg name.jieyouxu commentedon Nov 21, 2024
I'm going to reopen this issue as a possible enhancement to make these kinds of gating less confusing...
[-]What is `#[cfg(target_has_atomic)]` supposed to do?[/-][+]Nightly-only cfg gating like `#[cfg(target_has_atomic)]` is confusing[/+]Noratrieb commentedon Jan 5, 2025
What's the reason they are not feature gated? That seems like a bug, even if intended. Everything should be gated.
bjorn3 commentedon Jan 5, 2025
Knowing which feature gates are active requires evaluating cfg's for the crate root. And the cfg's cargo will see through
--print cfgcan't be feature gated as there is no source code available at that point. Cargo just runsrustc --print cfgonce for each target.jyn514 commentedon Apr 16, 2025
why does cargo need to know about this cfg?
well, we could ban ever using unstable cfgs in the crate root.
RalfJung commentedon Oct 24, 2026
I think then we have to change our intent. Rustc nightly should behave like stable by default.
We have a similar issue open for
cfg(target_feature), see #76842.