@@ -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:: {
@@ -300,7 +300,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
300
300
/// Must express features in the way Rust understands them.
301
301
///
302
302
/// 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 > {
304
304
let mut features: FxHashSet < Symbol > = Default :: default ( ) ;
305
305
306
306
// Add base features for the target.
@@ -316,7 +316,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
316
316
sess. target
317
317
. rust_target_features ( )
318
318
. iter ( )
319
- . filter ( |( _, gate, _) | gate. is_supported ( ) )
319
+ . filter ( |( _, gate, _) | gate. in_cfg ( ) )
320
320
. filter ( |( feature, _, _) | {
321
321
// skip checking special features, as LLVM may not understand them
322
322
if RUSTC_SPECIAL_FEATURES . contains ( feature) {
@@ -372,9 +372,9 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
372
372
sess. target
373
373
. rust_target_features ( )
374
374
. iter ( )
375
- . filter ( |( _, gate, _) | gate. is_supported ( ) )
375
+ . filter ( |( _, gate, _) | gate. in_cfg ( ) )
376
376
. 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 ( ) {
378
378
Some ( feature)
379
379
} else {
380
380
None
@@ -493,7 +493,7 @@ fn print_target_features(sess: &Session, tm: &llvm::TargetMachine, out: &mut Str
493
493
. rust_target_features ( )
494
494
. iter ( )
495
495
. filter_map ( |( feature, gate, _implied) | {
496
- if !gate. is_supported ( ) {
496
+ if !gate. in_cfg ( ) {
497
497
// Only list (experimentally) supported features.
498
498
return None ;
499
499
}
@@ -716,13 +716,15 @@ pub(crate) fn global_llvm_features(
716
716
} ;
717
717
sess. dcx ( ) . emit_warn ( unknown_feature) ;
718
718
}
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
+ }
726
728
}
727
729
}
728
730
0 commit comments