@@ -34,6 +34,9 @@ pub enum Stability {
34
34
/// particular for features are actually ABI configuration flags (not all targets are as nice as
35
35
/// RISC-V and have an explicit way to set the ABI separate from target features).
36
36
Forbidden { reason : & ' static str } ,
37
+ /// This feature can not be set via `-Ctarget-feature` or `#[target_feature]`, it can only be set
38
+ /// by target modifier flag. Target modifier flags are tracked to be consistent in linked modules.
39
+ EnabledByTargetModifierFlag { reason : & ' static str , flag : & ' static str } ,
37
40
}
38
41
use Stability :: * ;
39
42
@@ -49,6 +52,7 @@ impl<CTX> HashStable<CTX> for Stability {
49
52
Stability :: Forbidden { reason } => {
50
53
reason. hash_stable ( hcx, hasher) ;
51
54
}
55
+ Stability :: EnabledByTargetModifierFlag { .. } => { }
52
56
}
53
57
}
54
58
}
@@ -74,15 +78,23 @@ impl Stability {
74
78
Stability :: Unstable ( nightly_feature) => Some ( nightly_feature) ,
75
79
Stability :: Stable { .. } => None ,
76
80
Stability :: Forbidden { .. } => panic ! ( "forbidden features should not reach this far" ) ,
81
+ Stability :: EnabledByTargetModifierFlag { .. } => None ,
77
82
}
78
83
}
79
84
80
85
/// Returns whether the feature may be toggled via `#[target_feature]` or `-Ctarget-feature`.
81
86
/// (It might still be nightly-only even if this returns `true`, so make sure to also check
82
87
/// `requires_nightly`.)
83
- pub fn toggle_allowed ( & self ) -> Result < ( ) , & ' static str > {
88
+ pub fn toggle_allowed ( & self , flag_enabled : impl Fn ( & str ) -> bool ) -> Result < ( ) , & ' static str > {
84
89
match self {
85
90
Stability :: Forbidden { reason } => Err ( reason) ,
91
+ Stability :: EnabledByTargetModifierFlag { reason, flag } => {
92
+ if !flag_enabled ( * flag) {
93
+ Err ( reason)
94
+ } else {
95
+ Ok ( ( ) )
96
+ }
97
+ }
86
98
_ => Ok ( ( ) ) ,
87
99
}
88
100
}
@@ -423,6 +435,30 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
423
435
( "prfchw" , Unstable ( sym:: prfchw_target_feature) , & [ ] ) ,
424
436
( "rdrand" , Stable , & [ ] ) ,
425
437
( "rdseed" , Stable , & [ ] ) ,
438
+ (
439
+ "retpoline-external-thunk" ,
440
+ Stability :: EnabledByTargetModifierFlag {
441
+ reason : "use `retpoline-external-thunk` target modifier flag instead" ,
442
+ flag : "retpoline-external-thunk" ,
443
+ } ,
444
+ & [ ] ,
445
+ ) ,
446
+ (
447
+ "retpoline-indirect-branches" ,
448
+ Stability :: EnabledByTargetModifierFlag {
449
+ reason : "use `retpoline` target modifier flag instead" ,
450
+ flag : "retpoline" ,
451
+ } ,
452
+ & [ ] ,
453
+ ) ,
454
+ (
455
+ "retpoline-indirect-calls" ,
456
+ Stability :: EnabledByTargetModifierFlag {
457
+ reason : "use `retpoline` target modifier flag instead" ,
458
+ flag : "retpoline" ,
459
+ } ,
460
+ & [ ] ,
461
+ ) ,
426
462
( "rtm" , Unstable ( sym:: rtm_target_feature) , & [ ] ) ,
427
463
( "sha" , Stable , & [ "sse2" ] ) ,
428
464
( "sha512" , Unstable ( sym:: sha512_sm_x86) , & [ "avx2" ] ) ,
0 commit comments