@@ -17,17 +17,17 @@ pub const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"];
17
17
pub const RUSTC_SPECIAL_FEATURES : & [ & str ] = & [ "backchain" ] ;
18
18
19
19
/// 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:
21
21
/// this is initially a function since it can depend on `Target`, but for stable hashing
22
22
/// it needs to be something hashable to we have to make the type generic.
23
23
#[ derive( Debug , Clone , Copy ) ]
24
- pub enum Stability < AllowToggle > {
24
+ pub enum Stability < Toggleability > {
25
25
/// This target feature is stable, it can be used in `#[target_feature]` and
26
26
/// `#[cfg(target_feature)]`.
27
27
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]`,
29
29
/// determine if that is allowed.
30
- allow_toggle : AllowToggle ,
30
+ allow_toggle : Toggleability ,
31
31
} ,
32
32
/// This target feature is unstable. It is only present in `#[cfg(target_feature)]` on
33
33
/// nightly and using it in `#[target_feature]` requires enabling the given nightly feature.
@@ -36,7 +36,7 @@ pub enum Stability<AllowToggle> {
36
36
/// feature gate!
37
37
nightly_feature : Symbol ,
38
38
/// See `Stable::allow_toggle` comment above.
39
- allow_toggle : AllowToggle ,
39
+ allow_toggle : Toggleability ,
40
40
} ,
41
41
/// This feature can not be set via `-Ctarget-feature` or `#[target_feature]`, it can only be
42
42
/// 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>
50
50
/// `Stability` where `allow_toggle` has already been computed.
51
51
pub type StabilityComputed = Stability < Result < ( ) , & ' static str > > ;
52
52
53
- impl < CTX , AllowToggle : HashStable < CTX > > HashStable < CTX > for Stability < AllowToggle > {
53
+ impl < CTX , Toggleability : HashStable < CTX > > HashStable < CTX > for Stability < Toggleability > {
54
54
#[ inline]
55
55
fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
56
56
std:: mem:: discriminant ( self ) . hash_stable ( hcx, hasher) ;
@@ -69,15 +69,22 @@ impl<CTX, AllowToggle: HashStable<CTX>> HashStable<CTX> for Stability<AllowToggl
69
69
}
70
70
}
71
71
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`.)
75
76
pub fn in_cfg ( self ) -> bool {
76
77
!matches ! ( self , Stability :: Forbidden { .. } )
77
78
}
78
79
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`
81
88
pub fn requires_nightly ( self ) -> Option < Symbol > {
82
89
match self {
83
90
Stability :: Unstable { nightly_feature, .. } => Some ( nightly_feature) ,
@@ -88,7 +95,7 @@ impl<AllowToggle> Stability<AllowToggle> {
88
95
}
89
96
90
97
impl StabilityUncomputed {
91
- pub fn compute ( self , target : & Target ) -> StabilityComputed {
98
+ pub fn compute_toggleability ( self , target : & Target ) -> StabilityComputed {
92
99
use Stability :: * ;
93
100
match self {
94
101
Stable { allow_toggle } => Stable { allow_toggle : allow_toggle ( target) } ,
@@ -101,6 +108,9 @@ impl StabilityUncomputed {
101
108
}
102
109
103
110
impl 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`.)
104
114
pub fn allow_toggle ( self ) -> Result < ( ) , & ' static str > {
105
115
match self {
106
116
Stability :: Stable { allow_toggle } => allow_toggle,
0 commit comments