@@ -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
}
@@ -417,6 +429,30 @@ const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
417
429
( "prfchw" , Unstable ( sym:: prfchw_target_feature) , & [ ] ) ,
418
430
( "rdrand" , Stable , & [ ] ) ,
419
431
( "rdseed" , Stable , & [ ] ) ,
432
+ (
433
+ "retpoline-external-thunk" ,
434
+ Stability :: EnabledByTargetModifierFlag {
435
+ reason : "use `x86-retpoline` target modifier flag instead" ,
436
+ flag : "x86-retpoline" ,
437
+ } ,
438
+ & [ ] ,
439
+ ) ,
440
+ (
441
+ "retpoline-indirect-branches" ,
442
+ Stability :: EnabledByTargetModifierFlag {
443
+ reason : "use `x86-retpoline` target modifier flag instead" ,
444
+ flag : "x86-retpoline" ,
445
+ } ,
446
+ & [ ] ,
447
+ ) ,
448
+ (
449
+ "retpoline-indirect-calls" ,
450
+ Stability :: EnabledByTargetModifierFlag {
451
+ reason : "use `x86-retpoline` target modifier flag instead" ,
452
+ flag : "x86-retpoline" ,
453
+ } ,
454
+ & [ ] ,
455
+ ) ,
420
456
( "rtm" , Unstable ( sym:: rtm_target_feature) , & [ ] ) ,
421
457
( "sha" , Stable , & [ "sse2" ] ) ,
422
458
( "sha512" , Unstable ( sym:: sha512_sm_x86) , & [ "avx2" ] ) ,
0 commit comments