Skip to content

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

Open
@mystor

Description

@mystor

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-stabilityArea: `#[stable]`, `#[unstable]` etc.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions