about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2024-08-04 23:51:59 -0400
committerCaleb Zulawski <caleb.zulawski@gmail.com>2024-08-07 00:43:52 -0400
commit83276f568032f14b1af7e5cd9f7d928734af8d09 (patch)
treef137dd36c2b2121ecf72e267ec6fc2d7ba87cf73 /compiler/rustc_codegen_ssa
parent6b96a60611c5edaa107b109b5a50e58a64a33fc2 (diff)
downloadrust-83276f568032f14b1af7e5cd9f7d928734af8d09.tar.gz
rust-83276f568032f14b1af7e5cd9f7d928734af8d09.zip
Hide implicit target features from diagnostics when possible
Diffstat (limited to 'compiler/rustc_codegen_ssa')
-rw-r--r--compiler/rustc_codegen_ssa/src/target_features.rs28
1 files changed, 21 insertions, 7 deletions
diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs
index c84b844cd04..145b1ece230 100644
--- a/compiler/rustc_codegen_ssa/src/target_features.rs
+++ b/compiler/rustc_codegen_ssa/src/target_features.rs
@@ -6,6 +6,7 @@ use rustc_errors::Applicability;
 use rustc_hir::def::DefKind;
 use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
 use rustc_middle::bug;
+use rustc_middle::middle::codegen_fn_attrs::TargetFeature;
 use rustc_middle::query::Providers;
 use rustc_middle::ty::TyCtxt;
 use rustc_session::parse::feature_err;
@@ -18,7 +19,7 @@ pub fn from_target_feature(
     tcx: TyCtxt<'_>,
     attr: &ast::Attribute,
     supported_target_features: &UnordMap<String, Option<Symbol>>,
-    target_features: &mut Vec<Symbol>,
+    target_features: &mut Vec<TargetFeature>,
 ) {
     let Some(list) = attr.meta_item_list() else { return };
     let bad_item = |span| {
@@ -99,14 +100,27 @@ pub fn from_target_feature(
         }));
     }
 
-    // Add both explicit and implied target features, using a set to deduplicate
-    let mut target_features_set = UnordSet::new();
+    // Add explicit features
+    target_features.extend(
+        added_target_features.iter().copied().map(|name| TargetFeature { name, implied: false }),
+    );
+
+    // Add implied features
+    let mut implied_target_features = UnordSet::new();
     for feature in added_target_features.iter() {
-        target_features_set
+        implied_target_features
             .extend_unord(tcx.implied_target_features(*feature).clone().into_items());
     }
-    target_features_set.extend(added_target_features);
-    target_features.extend(target_features_set.into_sorted_stable_ord())
+    for feature in added_target_features.iter() {
+        implied_target_features.remove(feature);
+    }
+    target_features.extend(
+        implied_target_features
+            .into_sorted_stable_ord()
+            .iter()
+            .copied()
+            .map(|name| TargetFeature { name, implied: true }),
+    )
 }
 
 /// Computes the set of target features used in a function for the purposes of
@@ -115,7 +129,7 @@ fn asm_target_features(tcx: TyCtxt<'_>, did: DefId) -> &FxIndexSet<Symbol> {
     let mut target_features = tcx.sess.unstable_target_features.clone();
     if tcx.def_kind(did).has_codegen_attrs() {
         let attrs = tcx.codegen_fn_attrs(did);
-        target_features.extend(&attrs.target_features);
+        target_features.extend(attrs.target_features.iter().map(|feature| feature.name));
         match attrs.instruction_set {
             None => {}
             Some(InstructionSetAttr::ArmA32) => {