Skip to content

Commit 567b794

Browse files
committed
Refactor and fill out target feature lists
1 parent 12f5421 commit 567b794

File tree

5 files changed

+293
-360
lines changed

5 files changed

+293
-360
lines changed

compiler/rustc_codegen_gcc/src/gcc_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
6565

6666
let feature = backend_feature_name(s)?;
6767
// Warn against use of GCC specific feature names on the CLI.
68-
if diagnostics && !supported_features.iter().any(|&(v, _)| v == feature) {
69-
let rust_feature = supported_features.iter().find_map(|&(rust_feature, _)| {
68+
if diagnostics && !supported_features.iter().any(|&(v, _, _)| v == feature) {
69+
let rust_feature = supported_features.iter().find_map(|&(rust_feature, _, _)| {
7070
let gcc_features = to_gcc_features(sess, rust_feature);
7171
if gcc_features.contains(&feature) && !gcc_features.contains(&rust_feature) {
7272
Some(rust_feature)

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ pub fn target_features(
486486
sess.target
487487
.supported_target_features()
488488
.iter()
489-
.filter_map(|&(feature, gate)| {
489+
.filter_map(|&(feature, gate, _)| {
490490
if sess.is_nightly_build() || allow_unstable || gate.is_stable() {
491491
Some(feature)
492492
} else {

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
312312
sess.target
313313
.supported_target_features()
314314
.iter()
315-
.filter_map(|&(feature, gate)| {
315+
.filter_map(|&(feature, gate, _)| {
316316
if sess.is_nightly_build() || allow_unstable || gate.is_stable() {
317317
Some(feature)
318318
} else {
@@ -386,7 +386,7 @@ fn print_target_features(out: &mut String, sess: &Session, tm: &llvm::TargetMach
386386
.target
387387
.supported_target_features()
388388
.iter()
389-
.map(|(feature, _gate)| {
389+
.map(|(feature, _gate, _implied)| {
390390
// LLVM asserts that these are sorted. LLVM and Rust both use byte comparison for these strings.
391391
let llvm_feature = to_llvm_features(sess, *feature).llvm_feature_name;
392392
let desc =
@@ -571,17 +571,19 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
571571
let feature = backend_feature_name(sess, s)?;
572572
// Warn against use of LLVM specific feature names and unstable features on the CLI.
573573
if diagnostics {
574-
let feature_state = supported_features.iter().find(|&&(v, _)| v == feature);
574+
let feature_state = supported_features.iter().find(|&&(v, _, _)| v == feature);
575575
if feature_state.is_none() {
576-
let rust_feature = supported_features.iter().find_map(|&(rust_feature, _)| {
577-
let llvm_features = to_llvm_features(sess, rust_feature);
578-
if llvm_features.contains(feature) && !llvm_features.contains(rust_feature)
579-
{
580-
Some(rust_feature)
581-
} else {
582-
None
583-
}
584-
});
576+
let rust_feature =
577+
supported_features.iter().find_map(|&(rust_feature, _, _)| {
578+
let llvm_features = to_llvm_features(sess, rust_feature);
579+
if llvm_features.contains(feature)
580+
&& !llvm_features.contains(rust_feature)
581+
{
582+
Some(rust_feature)
583+
} else {
584+
None
585+
}
586+
});
585587
let unknown_feature = if let Some(rust_feature) = rust_feature {
586588
UnknownCTargetFeature {
587589
feature,
@@ -592,7 +594,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
592594
};
593595
sess.dcx().emit_warn(unknown_feature);
594596
} else if feature_state
595-
.is_some_and(|(_name, feature_gate)| !feature_gate.is_stable())
597+
.is_some_and(|(_name, feature_gate, _implied)| !feature_gate.is_stable())
596598
{
597599
// An unstable feature. Warn about using it.
598600
sess.dcx().emit_warn(UnstableCTargetFeature { feature });

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,17 @@ pub(crate) fn provide(providers: &mut Providers) {
160160
.target
161161
.supported_target_features()
162162
.iter()
163-
.map(|&(a, b)| (a.to_string(), b.as_feature_name()))
163+
.map(|&(a, b, _)| (a.to_string(), b.as_feature_name()))
164164
.collect()
165165
}
166166
},
167167
implied_target_features: |tcx, feature| {
168168
let implied_features = tcx
169169
.sess
170170
.target
171-
.implied_target_features()
171+
.supported_target_features()
172172
.iter()
173-
.map(|(f, i)| (Symbol::intern(f), i))
173+
.map(|(f, _, i)| (Symbol::intern(f), i))
174174
.collect::<FxHashMap<_, _>>();
175175

176176
// implied target features have their own implied target features, so we traverse the

0 commit comments

Comments
 (0)