about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-09-29 21:42:43 +0200
committerGitHub <noreply@github.com>2025-09-29 21:42:43 +0200
commit967e64279ac2695b1767f226d5b6e5cada3d67f4 (patch)
treeab1f2347b1693d374e13c33cf22d28b1311e7fec /src
parentfdb965f3f76e0bbb75ef20ddae033b7e689c7d3c (diff)
parent2e63708d39553ed882a20a198cdc0f269bb6cd30 (diff)
downloadrust-967e64279ac2695b1767f226d5b6e5cada3d67f4.tar.gz
rust-967e64279ac2695b1767f226d5b6e5cada3d67f4.zip
Rollup merge of #147133 - GuillaumeGomez:rm-loop-extract_cfg_from_attrs, r=lolbinarycat
Remove one loop in `extract_cfg_from_attrs`

Follow-up of https://github.com/rust-lang/rust/pull/138907.

r? lolbinarycat
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/clean/types.rs16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index 4eb32585ffb..6e3dfa0ac22 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -1084,8 +1084,8 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
 
     let mut changed_auto_active_status = None;
 
-    // First we get all `doc(auto_cfg)` attributes.
-    for attr in attrs.clone() {
+    // We get all `doc(auto_cfg)`, `cfg` and `target_feature` attributes.
+    for attr in attrs {
         if let Some(ident) = attr.ident()
             && ident.name == sym::doc
             && let Some(attrs) = attr.meta_item_list()
@@ -1146,15 +1146,9 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
                     }
                 }
             }
-        }
-    }
-
-    // If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
-    // `doc(cfg())` overrides `cfg()`).
-    for attr in attrs {
-        if let hir::Attribute::Parsed(AttributeKind::TargetFeature { features, .. }) = attr {
-            // treat #[target_feature(enable = "feat")] attributes as if they were
-            // #[doc(cfg(target_feature = "feat"))] attributes as well
+        } else if let hir::Attribute::Parsed(AttributeKind::TargetFeature { features, .. }) = attr {
+            // Treat `#[target_feature(enable = "feat")]` attributes as if they were
+            // `#[doc(cfg(target_feature = "feat"))]` attributes as well.
             for (feature, _) in features {
                 cfg_info.current_cfg &= Cfg::Cfg(sym::target_feature, Some(*feature));
             }