Skip to content
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

Feature gate for unstable target_feature values not being checked on nightly #76842

Open
mystor opened this issue Sep 17, 2020 · 2 comments
Open
Labels
A-stability Area: issues related to #[stable] and #[unstable] attributes themselves. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mystor
Copy link
Contributor

mystor commented Sep 17, 2020

I tried this code: playpen

#[cfg(target_feature="mmx")]
compile_fail!("we have mmx");

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 behind mmx_target_feature as far as I can tell)

("mmx", Some(sym::mmx_target_feature)),

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 enabling mmx_target_feature was ignored, only considering the current release channel.

I believe this is occurring due to the feature gate logic for the target_feature config flag not being checked within the compiler. This mismatch lead me to believe that an unstable target_feature flag was actually stable, and write code using it, before realizing it won't function outside of the nightly channel.

Meta

rustc --version --verbose:
stable:

rustc 1.46.0 (04488afe3 2020-08-24)
binary: rustc
commit-hash: 04488afe34512aa4c33566eb16d8c912a3ae04f9
commit-date: 2020-08-24
host: x86_64-unknown-linux-gnu
release: 1.46.0
LLVM version: 10.0

nightly:

rustc 1.47.0-nightly (bf4342114 2020-08-25)
binary: rustc
commit-hash: bf4342114e357f2934d59e12e31e94532ddb2adf
commit-date: 2020-08-25
host: x86_64-unknown-linux-gnu
release: 1.47.0-nightly
LLVM version: 11.0

(this also occurs on rust-playpen at time of filing: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=4c58960ac6fc536a2da930d6c0b3d8e9)

@mystor mystor added the C-bug Category: This is a bug. label Sep 17, 2020
@m-ou-se
Copy link
Member

m-ou-se commented Sep 17, 2020

Looks like all feature gated target_features are made available on nightly regardless of enabled features, here:

supported_target_features(sess)
.iter()
.filter_map(|&(feature, gate)| {
if UnstableFeatures::from_environment().is_nightly_build() || gate.is_none() {
Some(feature)
} else {
None
}
})

@jyn514 jyn514 added requires-nightly This issue requires a nightly compiler in some way. A-stability Area: issues related to #[stable] and #[unstable] attributes themselves. labels Sep 17, 2020
@jyn514 jyn514 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 Sep 17, 2020
@jyn514 jyn514 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 17, 2020
@m-ou-se
Copy link
Member

m-ou-se commented Sep 17, 2020

It seems like all target_features were always available on nightly when cfg_target_feature was still unstable. So, cfg(target_feature = "mmx") was not gated behind mmx_target_feature, but only behind cfg_target_feature. #49664 stabilized cfg_target_feature, and added the lines I quoted above to let only stable target_features (not mmx) through on stable, but didn't change the behaviour on nightly. So that's when the 'unstable' cfg(target_feature = "mmx") suddenly became ungated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stability Area: issues related to #[stable] and #[unstable] attributes themselves. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants