@@ -34,6 +34,9 @@ pub enum Stability {
3434 /// particular for features are actually ABI configuration flags (not all targets are as nice as
3535 /// RISC-V and have an explicit way to set the ABI separate from target features).
3636 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 } ,
3740}
3841use Stability :: * ;
3942
@@ -49,6 +52,7 @@ impl<CTX> HashStable<CTX> for Stability {
4952 Stability :: Forbidden { reason } => {
5053 reason. hash_stable ( hcx, hasher) ;
5154 }
55+ Stability :: EnabledByTargetModifierFlag { .. } => { }
5256 }
5357 }
5458}
@@ -74,15 +78,23 @@ impl Stability {
7478 Stability :: Unstable ( nightly_feature) => Some ( nightly_feature) ,
7579 Stability :: Stable { .. } => None ,
7680 Stability :: Forbidden { .. } => panic ! ( "forbidden features should not reach this far" ) ,
81+ Stability :: EnabledByTargetModifierFlag { .. } => None ,
7782 }
7883 }
7984
8085 /// Returns whether the feature may be toggled via `#[target_feature]` or `-Ctarget-feature`.
8186 /// (It might still be nightly-only even if this returns `true`, so make sure to also check
8287 /// `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 > {
8489 match self {
8590 Stability :: Forbidden { reason } => Err ( reason) ,
91+ Stability :: EnabledByTargetModifierFlag { reason, flag } => {
92+ if !flag_enabled ( * flag) {
93+ Err ( reason)
94+ } else {
95+ Ok ( ( ) )
96+ }
97+ }
8698 _ => Ok ( ( ) ) ,
8799 }
88100 }
@@ -418,6 +430,30 @@ const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
418430 ( "prfchw" , Unstable ( sym:: prfchw_target_feature) , & [ ] ) ,
419431 ( "rdrand" , Stable , & [ ] ) ,
420432 ( "rdseed" , Stable , & [ ] ) ,
433+ (
434+ "retpoline-external-thunk" ,
435+ Stability :: EnabledByTargetModifierFlag {
436+ reason : "use `x86-retpoline` target modifier flag instead" ,
437+ flag : "x86-retpoline" ,
438+ } ,
439+ & [ ] ,
440+ ) ,
441+ (
442+ "retpoline-indirect-branches" ,
443+ Stability :: EnabledByTargetModifierFlag {
444+ reason : "use `x86-retpoline` target modifier flag instead" ,
445+ flag : "x86-retpoline" ,
446+ } ,
447+ & [ ] ,
448+ ) ,
449+ (
450+ "retpoline-indirect-calls" ,
451+ Stability :: EnabledByTargetModifierFlag {
452+ reason : "use `x86-retpoline` target modifier flag instead" ,
453+ flag : "x86-retpoline" ,
454+ } ,
455+ & [ ] ,
456+ ) ,
421457 ( "rtm" , Unstable ( sym:: rtm_target_feature) , & [ ] ) ,
422458 ( "sha" , Stable , & [ "sse2" ] ) ,
423459 ( "sha512" , Unstable ( sym:: sha512_sm_x86) , & [ "avx2" ] ) ,
0 commit comments