@@ -17,17 +17,17 @@ pub const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"];
1717pub const RUSTC_SPECIAL_FEATURES : & [ & str ] = & [ "backchain" ] ;
1818
1919/// Stability information for target features.
20- /// `AllowToggle ` is the type storing whether (un)stable features can be toggled:
20+ /// `Toggleability ` is the type storing whether (un)stable features can be toggled:
2121/// this is initially a function since it can depend on `Target`, but for stable hashing
2222/// it needs to be something hashable to we have to make the type generic.
2323#[ derive( Debug , Clone , Copy ) ]
24- pub enum Stability < AllowToggle > {
24+ pub enum Stability < Toggleability > {
2525 /// This target feature is stable, it can be used in `#[target_feature]` and
2626 /// `#[cfg(target_feature)]`.
2727 Stable {
28- /// When enabling/dsiabling the feature via `-Ctarget-feature` or `#[target_feature]`,
28+ /// When enabling/disabling the feature via `-Ctarget-feature` or `#[target_feature]`,
2929 /// determine if that is allowed.
30- allow_toggle : AllowToggle ,
30+ allow_toggle : Toggleability ,
3131 } ,
3232 /// This target feature is unstable. It is only present in `#[cfg(target_feature)]` on
3333 /// nightly and using it in `#[target_feature]` requires enabling the given nightly feature.
@@ -36,7 +36,7 @@ pub enum Stability<AllowToggle> {
3636 /// feature gate!
3737 nightly_feature : Symbol ,
3838 /// See `Stable::allow_toggle` comment above.
39- allow_toggle : AllowToggle ,
39+ allow_toggle : Toggleability ,
4040 } ,
4141 /// This feature can not be set via `-Ctarget-feature` or `#[target_feature]`, it can only be
4242 /// set in the basic target definition. It is never set in `cfg(target_feature)`. Used in
@@ -50,7 +50,7 @@ pub type StabilityUncomputed = Stability<fn(&Target) -> Result<(), &'static str>
5050/// `Stability` where `allow_toggle` has already been computed.
5151pub type StabilityComputed = Stability < Result < ( ) , & ' static str > > ;
5252
53- impl < CTX , AllowToggle : HashStable < CTX > > HashStable < CTX > for Stability < AllowToggle > {
53+ impl < CTX , Toggleability : HashStable < CTX > > HashStable < CTX > for Stability < Toggleability > {
5454 #[ inline]
5555 fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
5656 std:: mem:: discriminant ( self ) . hash_stable ( hcx, hasher) ;
@@ -69,15 +69,22 @@ impl<CTX, AllowToggle: HashStable<CTX>> HashStable<CTX> for Stability<AllowToggl
6969 }
7070}
7171
72- impl < AllowToggle > Stability < AllowToggle > {
73- /// Returns whether the feature can be queried in `cfg` ever.
74- /// (It might still be nightly-only even if this returns `true`).
72+ impl < Toggleability > Stability < Toggleability > {
73+ /// Returns whether the feature can be used in `cfg(target_feature)` ever.
74+ /// (It might still be nightly-only even if this returns `true`, so make sure to also check
75+ /// `requires_nightly`.)
7576 pub fn in_cfg ( self ) -> bool {
7677 !matches ! ( self , Stability :: Forbidden { .. } )
7778 }
7879
79- /// Returns the nightly feature that is required to toggle or query this target feature. Ensure
80- /// to also check `allow_toggle()` before allowing to toggle!
80+ /// Returns the nightly feature that is required to toggle this target feature via
81+ /// `#[target_feature]`/`-Ctarget-feature` or to test it via `cfg(target_feature)`.
82+ /// (For `cfg` we only care whether the feature is nightly or not, we don't require
83+ /// the feature gate to actually be enabled when using a nightly compiler.)
84+ ///
85+ /// Before calling this, ensure the feature is even permitted for this use:
86+ /// - for `#[target_feature]`/`-Ctarget-feature`, check `allow_toggle()`
87+ /// - for `cfg(target_feature)`, check `in_cfg`
8188 pub fn requires_nightly ( self ) -> Option < Symbol > {
8289 match self {
8390 Stability :: Unstable { nightly_feature, .. } => Some ( nightly_feature) ,
@@ -88,7 +95,7 @@ impl<AllowToggle> Stability<AllowToggle> {
8895}
8996
9097impl StabilityUncomputed {
91- pub fn compute ( self , target : & Target ) -> StabilityComputed {
98+ pub fn compute_toggleability ( self , target : & Target ) -> StabilityComputed {
9299 use Stability :: * ;
93100 match self {
94101 Stable { allow_toggle } => Stable { allow_toggle : allow_toggle ( target) } ,
@@ -101,6 +108,9 @@ impl StabilityUncomputed {
101108}
102109
103110impl StabilityComputed {
111+ /// Returns whether the feature may be toggled via `#[target_feature]` or `-Ctarget-feature`.
112+ /// (It might still be nightly-only even if this returns `true`, so make sure to also check
113+ /// `requires_nightly`.)
104114 pub fn allow_toggle ( self ) -> Result < ( ) , & ' static str > {
105115 match self {
106116 Stability :: Stable { allow_toggle } => allow_toggle,
0 commit comments