Skip to content

Commit a1374f5

Browse files
committed
generalize 'forbidden feature' concept so that even (un)stable feature can be invalid to toggle
Also rename some things for extra clarity
1 parent 691aec2 commit a1374f5

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ codegen_gcc_lto_not_supported =
99
LTO is not supported. You may get a linker error.
1010
1111
codegen_gcc_forbidden_ctarget_feature =
12-
target feature `{$feature}` cannot be toggled with `-Ctarget-feature`
12+
target feature `{$feature}` cannot be toggled with `-Ctarget-feature`: {$reason}
1313
1414
codegen_gcc_unwinding_inline_asm =
1515
GCC backend does not support unwinding from inline asm

src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub(crate) struct UnstableCTargetFeature<'a> {
2828
#[diag(codegen_gcc_forbidden_ctarget_feature)]
2929
pub(crate) struct ForbiddenCTargetFeature<'a> {
3030
pub feature: &'a str,
31+
pub reason: &'a str,
3132
}
3233

3334
#[derive(Subdiagnostic)]

src/gcc_util.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_codegen_ssa::errors::TargetFeatureDisableOrEnable;
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_middle::bug;
77
use rustc_session::Session;
8-
use rustc_target::target_features::{RUSTC_SPECIFIC_FEATURES, Stability};
8+
use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES;
99
use smallvec::{SmallVec, smallvec};
1010

1111
use crate::errors::{
@@ -94,13 +94,15 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
9494
};
9595
sess.dcx().emit_warn(unknown_feature);
9696
}
97-
Some((_, Stability::Stable, _)) => {}
98-
Some((_, Stability::Unstable(_), _)) => {
99-
// An unstable feature. Warn about using it.
100-
sess.dcx().emit_warn(UnstableCTargetFeature { feature });
101-
}
102-
Some((_, Stability::Forbidden { .. }, _)) => {
103-
sess.dcx().emit_err(ForbiddenCTargetFeature { feature });
97+
Some((_, stability, _)) => {
98+
if let Err(reason) = stability.compute(&sess.target).allow_toggle() {
99+
sess.dcx().emit_warn(ForbiddenCTargetFeature { feature, reason });
100+
} else if stability.requires_nightly().is_some() {
101+
// An unstable feature. Warn about using it. (It makes little sense
102+
// to hard-error here since we just warn about fully unknown
103+
// features above).
104+
sess.dcx().emit_warn(UnstableCTargetFeature { feature });
105+
}
104106
}
105107
}
106108

src/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ impl CodegenBackend for GccCodegenBackend {
260260
.join(sess)
261261
}
262262

263-
fn target_features(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
264-
target_features(sess, allow_unstable, &self.target_info)
263+
fn target_features_cfg(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
264+
target_features_cfg(sess, allow_unstable, &self.target_info)
265265
}
266266
}
267267

@@ -472,7 +472,8 @@ fn to_gcc_opt_level(optlevel: Option<OptLevel>) -> OptimizationLevel {
472472
}
473473
}
474474

475-
pub fn target_features(
475+
/// Returns the features that should be set in `cfg(target_feature)`.
476+
fn target_features_cfg(
476477
sess: &Session,
477478
allow_unstable: bool,
478479
target_info: &LockedTargetInfo,
@@ -481,9 +482,9 @@ pub fn target_features(
481482
sess.target
482483
.rust_target_features()
483484
.iter()
484-
.filter(|(_, gate, _)| gate.is_supported())
485+
.filter(|(_, gate, _)| gate.in_cfg())
485486
.filter_map(|&(feature, gate, _)| {
486-
if sess.is_nightly_build() || allow_unstable || gate.is_stable() {
487+
if sess.is_nightly_build() || allow_unstable || gate.requires_nightly().is_none() {
487488
Some(feature)
488489
} else {
489490
None

0 commit comments

Comments
 (0)