@@ -17,6 +17,13 @@ pub enum Stability {
1717 /// This target feature is stable, it can be used in `#[target_feature]` and
1818 /// `#[cfg(target_feature)]`.
1919 Stable ,
20+ /// This target feature is cfg-stable. It can be used for `#[cfg(target_feature)]` on stable,
21+ /// but using it in `#[target_feature]` requires the given nightly feature.
22+ CfgOnlyStable (
23+ /// This must be a *language* feature, or else rustc will ICE when reporting a missing
24+ /// feature gate!
25+ Symbol ,
26+ ) ,
2027 /// This target feature is unstable. It is only present in `#[cfg(target_feature)]` on
2128 /// nightly and using it in `#[target_feature]` requires enabling the given nightly feature.
2229 Unstable (
@@ -37,7 +44,10 @@ impl Stability {
3744 /// (It might still be nightly-only even if this returns `true`, so make sure to also check
3845 /// `requires_nightly`.)
3946 pub fn in_cfg ( & self ) -> bool {
40- matches ! ( self , Stability :: Stable | Stability :: Unstable { .. } )
47+ matches ! (
48+ self ,
49+ Stability :: Stable | Stability :: CfgOnlyStable { .. } | Stability :: Unstable { .. }
50+ )
4151 }
4252
4353 /// Returns the nightly feature that is required to toggle this target feature via
@@ -48,9 +58,19 @@ impl Stability {
4858 /// Before calling this, ensure the feature is even permitted for this use:
4959 /// - for `#[target_feature]`/`-Ctarget-feature`, check `toggle_allowed()`
5060 /// - for `cfg(target_feature)`, check `in_cfg()`
51- pub fn requires_nightly ( & self ) -> Option < Symbol > {
61+ ///
62+ /// The `is_cfg` parameter is used to determine whether it will be used in
63+ /// `cfg(target_feature)` (true) or `#[target_feature]`/`-Ctarget-feature` (false)
64+ pub fn requires_nightly ( & self , is_cfg : bool ) -> Option < Symbol > {
5265 match * self {
5366 Stability :: Unstable ( nightly_feature) => Some ( nightly_feature) ,
67+ Stability :: CfgOnlyStable ( nightly_feature) => {
68+ if is_cfg {
69+ None
70+ } else {
71+ Some ( nightly_feature)
72+ }
73+ }
5474 Stability :: Stable { .. } => None ,
5575 Stability :: Forbidden { .. } => panic ! ( "forbidden features should not reach this far" ) ,
5676 }
@@ -61,7 +81,9 @@ impl Stability {
6181 /// `requires_nightly`.)
6282 pub fn toggle_allowed ( & self ) -> Result < ( ) , & ' static str > {
6383 match self {
64- Stability :: Unstable ( _) | Stability :: Stable { .. } => Ok ( ( ) ) ,
84+ Stability :: Unstable ( _) | Stability :: CfgOnlyStable ( _) | Stability :: Stable { .. } => {
85+ Ok ( ( ) )
86+ }
6587 Stability :: Forbidden { reason } => Err ( reason) ,
6688 }
6789 }
0 commit comments