Repository navigation
Feature gate for unstable target_feature values not being checked on nightly #76842
Copy link
Copy link
Open
Labels
A-stabilityArea: `#[stable]`, `#[unstable]` etc.Area: `#[stable]`, `#[unstable]` etc.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Description
Activity
Looks like all feature gated target_features are made available on nightly regardless of enabled features, here:
rust/compiler/rustc_codegen_llvm/src/llvm_util.rs
Lines 292 to 300 in 7bdb5de
supported_target_features(sess) .iter() .filter_map(|&(feature, gate)| { if UnstableFeatures::from_environment().is_nightly_build() || gate.is_none() { Some(feature) } else { None } }) - addedrequires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.A-stabilityArea: `#[stable]`, `#[unstable]` etc.Area: `#[stable]`, `#[unstable]` etc.
on Sep 17, 2020 - changed the title
[-]Feature gate for unstable target_feature values not being checked[/-][+]Feature gate for unstable target_feature values not being checked on nightly[/+]on Sep 17, 2020 - addedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
on Sep 17, 2020 It seems like all target_features were always available on nightly when
cfg_target_featurewas still unstable. So,cfg(target_feature = "mmx")was not gated behindmmx_target_feature, but only behindcfg_target_feature. #49664 stabilizedcfg_target_feature, and added the lines I quoted above to let only stable target_features (notmmx) through on stable, but didn't change the behaviour on nightly. So that's when the 'unstable'cfg(target_feature = "mmx")suddenly became ungated.
Metadata
Metadata
Assignees
Labels
A-stabilityArea: `#[stable]`, `#[unstable]` etc.Area: `#[stable]`, `#[unstable]` etc.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
I tried this code: playpen
I expected to see this happen:
This code uses a feature-gated
cfg(, without enabling the feature. I would expect this to produce a build warning about using an unstable cfg gate, and produce no build error on all channels.(
target_feature="mmx"is currently gated behindmmx_target_featureas far as I can tell)rust/compiler/rustc_codegen_llvm/src/llvm_util.rs
Line 206 in 7bdb5de
Instead, this happened:
On stable, the gate was ignored as expected, but on the nightly channel the cfg check passed, causing the
compile_fail!to be included in the source. The lack of a feature gate enablingmmx_target_featurewas ignored, only considering the current release channel.I believe this is occurring due to the feature gate logic for the
target_featureconfig flag not being checked within the compiler. This mismatch lead me to believe that an unstabletarget_featureflag was actually stable, and write code using it, before realizing it won't function outside of the nightly channel.Meta
rustc --version --verbose:stable:
nightly:
(this also occurs on rust-playpen at time of filing: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=4c58960ac6fc536a2da930d6c0b3d8e9)