@@ -17,7 +17,7 @@ use rustc_session::Session;
17
17
use rustc_session:: config:: { PrintKind , PrintRequest } ;
18
18
use rustc_span:: symbol:: Symbol ;
19
19
use 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 } ;
21
21
22
22
use crate :: back:: write:: create_informational_target_machine;
23
23
use crate :: errors:: {
@@ -297,7 +297,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
297
297
/// Must express features in the way Rust understands them.
298
298
///
299
299
/// 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 > {
301
301
let mut features: FxHashSet < Symbol > = Default :: default ( ) ;
302
302
303
303
// Add base features for the target.
@@ -313,7 +313,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
313
313
sess. target
314
314
. rust_target_features ( )
315
315
. iter ( )
316
- . filter ( |( _, gate, _) | gate. is_supported ( ) )
316
+ . filter ( |( _, gate, _) | gate. in_cfg ( ) )
317
317
. filter ( |( feature, _, _) | {
318
318
// skip checking special features, as LLVM may not understand them
319
319
if RUSTC_SPECIAL_FEATURES . contains ( feature) {
@@ -369,9 +369,9 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
369
369
sess. target
370
370
. rust_target_features ( )
371
371
. iter ( )
372
- . filter ( |( _, gate, _) | gate. is_supported ( ) )
372
+ . filter ( |( _, gate, _) | gate. in_cfg ( ) )
373
373
. 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 ( ) {
375
375
Some ( feature)
376
376
} else {
377
377
None
@@ -490,7 +490,7 @@ fn print_target_features(sess: &Session, tm: &llvm::TargetMachine, out: &mut Str
490
490
. rust_target_features ( )
491
491
. iter ( )
492
492
. filter_map ( |( feature, gate, _implied) | {
493
- if !gate. is_supported ( ) {
493
+ if !gate. in_cfg ( ) {
494
494
// Only list (experimentally) supported features.
495
495
return None ;
496
496
}
@@ -713,13 +713,15 @@ pub(crate) fn global_llvm_features(
713
713
} ;
714
714
sess. dcx ( ) . emit_warn ( unknown_feature) ;
715
715
}
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
+ }
723
725
}
724
726
}
725
727
0 commit comments