about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2025-02-25 13:58:31 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2025-03-05 09:20:27 +1100
commit1df93fd6a7a164ebd8b7868d9382e3fb37f4642e (patch)
tree2df5f10ee8a0cee7ba156d3a0178df7035e8cc34
parentf9e0239a7bc813b4aceffc7f069f4797cde3175c (diff)
downloadrust-1df93fd6a7a164ebd8b7868d9382e3fb37f4642e.tar.gz
rust-1df93fd6a7a164ebd8b7868d9382e3fb37f4642e.zip
Avoid double interning of feature names.
Also improve some comments.
-rw-r--r--compiler/rustc_codegen_llvm/src/llvm_util.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs
index 5cc4f4ab9e6..23e8a986564 100644
--- a/compiler/rustc_codegen_llvm/src/llvm_util.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs
@@ -313,11 +313,11 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
     // We do *not* add the -Ctarget-features there, and instead duplicate the logic for that below.
     // The reason is that if LLVM considers a feature implied but we do not, we don't want that to
     // show up in `cfg`. That way, `cfg` is entirely under our control -- except for the handling of
-    // the target CPU, that is still expanded to target features (with all their implied features) by
-    // LLVM.
+    // the target CPU, that is still expanded to target features (with all their implied features)
+    // by LLVM.
     let target_machine = create_informational_target_machine(sess, true);
-    // Compute which of the known target features are enabled in the 'base' target machine.
-    // We only consider "supported" features; "forbidden" features are not reflected in `cfg` as of now.
+    // Compute which of the known target features are enabled in the 'base' target machine. We only
+    // consider "supported" features; "forbidden" features are not reflected in `cfg` as of now.
     features.extend(
         sess.target
             .rust_target_features()
@@ -344,7 +344,7 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
             .map(|(feature, _, _)| Symbol::intern(feature)),
     );
 
-    // Add enabled features
+    // Add enabled and remove disabled features.
     for (enabled, feature) in
         sess.opts.cg.target_feature.split(',').filter_map(|s| match s.chars().next() {
             Some('+') => Some((true, Symbol::intern(&s[1..]))),
@@ -398,13 +398,12 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
             if allow_unstable
                 || (gate.in_cfg() && (sess.is_nightly_build() || gate.requires_nightly().is_none()))
             {
-                Some(*feature)
+                Some(Symbol::intern(feature))
             } else {
                 None
             }
         })
-        .filter(|feature| features.contains(&Symbol::intern(feature)))
-        .map(|feature| Symbol::intern(feature))
+        .filter(|feature| features.contains(&feature))
         .collect()
 }