@@ -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:: {
@@ -300,7 +300,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
300300/// Must express features in the way Rust understands them.
301301///
302302/// We do not have to worry about RUSTC_SPECIFIC_FEATURES here, those are handled outside codegen.
303- pub fn target_features ( sess : & Session , allow_unstable : bool ) -> Vec < Symbol > {
303+ pub fn target_features_cfg ( sess : & Session , allow_unstable : bool ) -> Vec < Symbol > {
304304 let mut features: FxHashSet < Symbol > = Default :: default ( ) ;
305305
306306 // Add base features for the target.
@@ -316,7 +316,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
316316 sess. target
317317 . rust_target_features ( )
318318 . iter ( )
319- . filter ( |( _, gate, _) | gate. is_supported ( ) )
319+ . filter ( |( _, gate, _) | gate. in_cfg ( ) )
320320 . filter ( |( feature, _, _) | {
321321 // skip checking special features, as LLVM may not understand them
322322 if RUSTC_SPECIAL_FEATURES . contains ( feature) {
@@ -372,9 +372,9 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
372372 sess. target
373373 . rust_target_features ( )
374374 . iter ( )
375- . filter ( |( _, gate, _) | gate. is_supported ( ) )
375+ . filter ( |( _, gate, _) | gate. in_cfg ( ) )
376376 . filter_map ( |& ( feature, gate, _) | {
377- if sess. is_nightly_build ( ) || allow_unstable || gate. is_stable ( ) {
377+ if sess. is_nightly_build ( ) || allow_unstable || gate. requires_nightly ( ) . is_none ( ) {
378378 Some ( feature)
379379 } else {
380380 None
@@ -493,7 +493,7 @@ fn print_target_features(sess: &Session, tm: &llvm::TargetMachine, out: &mut Str
493493 . rust_target_features ( )
494494 . iter ( )
495495 . filter_map ( |( feature, gate, _implied) | {
496- if !gate. is_supported ( ) {
496+ if !gate. in_cfg ( ) {
497497 // Only list (experimentally) supported features.
498498 return None ;
499499 }
@@ -716,13 +716,15 @@ pub(crate) fn global_llvm_features(
716716 } ;
717717 sess. dcx ( ) . emit_warn ( unknown_feature) ;
718718 }
719- Some ( ( _, Stability :: Stable , _) ) => { }
720- Some ( ( _, Stability :: Unstable ( _) , _) ) => {
721- // An unstable feature. Warn about using it.
722- sess. dcx ( ) . emit_warn ( UnstableCTargetFeature { feature } ) ;
723- }
724- Some ( ( _, Stability :: Forbidden { reason } , _) ) => {
725- sess. dcx ( ) . emit_warn ( ForbiddenCTargetFeature { feature, reason } ) ;
719+ Some ( ( _, stability, _) ) => {
720+ if let Err ( reason) = stability. compute ( & sess. target ) . allow_toggle ( ) {
721+ sess. dcx ( ) . emit_warn ( ForbiddenCTargetFeature { feature, reason } ) ;
722+ } else if stability. requires_nightly ( ) . is_some ( ) {
723+ // An unstable feature. Warn about using it. (It makes little sense
724+ // to hard-error here since we just warn about fully unknown
725+ // features above).
726+ sess. dcx ( ) . emit_warn ( UnstableCTargetFeature { feature } ) ;
727+ }
726728 }
727729 }
728730
0 commit comments