@@ -17,7 +17,7 @@ use rustc_session::Session;
1717use rustc_session:: config:: { PrintKind , PrintRequest } ;
1818use rustc_span:: symbol:: Symbol ;
1919use rustc_target:: spec:: { MergeFunctions , PanicStrategy , SmallDataThresholdSupport } ;
20- use rustc_target:: target_features:: { RUSTC_SPECIAL_FEATURES , RUSTC_SPECIFIC_FEATURES , Stability } ;
20+ use rustc_target:: target_features:: { RUSTC_SPECIAL_FEATURES , RUSTC_SPECIFIC_FEATURES } ;
2121
2222use crate :: back:: write:: create_informational_target_machine;
2323use crate :: errors:: {
@@ -297,7 +297,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
297297/// Must express features in the way Rust understands them.
298298///
299299/// We do not have to worry about RUSTC_SPECIFIC_FEATURES here, those are handled outside codegen.
300- pub fn target_features ( sess : & Session , allow_unstable : bool ) -> Vec < Symbol > {
300+ pub fn target_features_cfg ( sess : & Session , allow_unstable : bool ) -> Vec < Symbol > {
301301 let mut features: FxHashSet < Symbol > = Default :: default ( ) ;
302302
303303 // Add base features for the target.
@@ -313,7 +313,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
313313 sess. target
314314 . rust_target_features ( )
315315 . iter ( )
316- . filter ( |( _, gate, _) | gate. is_supported ( ) )
316+ . filter ( |( _, gate, _) | gate. in_cfg ( ) )
317317 . filter ( |( feature, _, _) | {
318318 // skip checking special features, as LLVM may not understand them
319319 if RUSTC_SPECIAL_FEATURES . contains ( feature) {
@@ -369,9 +369,9 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
369369 sess. target
370370 . rust_target_features ( )
371371 . iter ( )
372- . filter ( |( _, gate, _) | gate. is_supported ( ) )
372+ . filter ( |( _, gate, _) | gate. in_cfg ( ) )
373373 . filter_map ( |& ( feature, gate, _) | {
374- if sess. is_nightly_build ( ) || allow_unstable || gate. is_stable ( ) {
374+ if sess. is_nightly_build ( ) || allow_unstable || gate. requires_nightly ( ) . is_none ( ) {
375375 Some ( feature)
376376 } else {
377377 None
@@ -490,7 +490,7 @@ fn print_target_features(sess: &Session, tm: &llvm::TargetMachine, out: &mut Str
490490 . rust_target_features ( )
491491 . iter ( )
492492 . filter_map ( |( feature, gate, _implied) | {
493- if !gate. is_supported ( ) {
493+ if !gate. in_cfg ( ) {
494494 // Only list (experimentally) supported features.
495495 return None ;
496496 }
@@ -713,13 +713,15 @@ pub(crate) fn global_llvm_features(
713713 } ;
714714 sess. dcx ( ) . emit_warn ( unknown_feature) ;
715715 }
716- Some ( ( _, Stability :: Stable , _) ) => { }
717- Some ( ( _, Stability :: Unstable ( _) , _) ) => {
718- // An unstable feature. Warn about using it.
719- sess. dcx ( ) . emit_warn ( UnstableCTargetFeature { feature } ) ;
720- }
721- Some ( ( _, Stability :: Forbidden { reason } , _) ) => {
722- sess. dcx ( ) . emit_warn ( ForbiddenCTargetFeature { feature, reason } ) ;
716+ Some ( ( _, stability, _) ) => {
717+ if let Err ( reason) = stability. compute ( & sess. target ) . allow_toggle ( ) {
718+ sess. dcx ( ) . emit_warn ( ForbiddenCTargetFeature { feature, reason } ) ;
719+ } else if stability. requires_nightly ( ) . is_some ( ) {
720+ // An unstable feature. Warn about using it. (It makes little sense
721+ // to hard-error here since we just warn about fully unknown
722+ // features above).
723+ sess. dcx ( ) . emit_warn ( UnstableCTargetFeature { feature } ) ;
724+ }
723725 }
724726 }
725727
0 commit comments