about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2023-09-10 09:17:24 -0700
committerGitHub <noreply@github.com>2023-09-10 09:17:24 -0700
commitc79b960747487f6724ebe5b163a22c82a2b636d3 (patch)
tree3f9933ac712de6a558f1da9d1dddecb8d8bb9633
parentc3e5ad448b87be31e570c048cf7ba3b1e7daec44 (diff)
downloadrust-c79b960747487f6724ebe5b163a22c82a2b636d3.tar.gz
rust-c79b960747487f6724ebe5b163a22c82a2b636d3.zip
rustdoc: filter before storing in vec
-rw-r--r--src/librustdoc/html/render/context.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs
index 6a79cdfb431..0bc10c5e10f 100644
--- a/src/librustdoc/html/render/context.rs
+++ b/src/librustdoc/html/render/context.rs
@@ -159,8 +159,15 @@ impl SharedContext<'_> {
     ) -> Vec<&'a formats::Impl> {
         let tcx = self.tcx;
         let cache = &self.cache;
-        let mut v: Vec<&formats::Impl> =
-            cache.impls.get(&did).map(Vec::as_slice).unwrap_or(&[]).iter().collect();
+        let mut saw_impls = FxHashSet::default();
+        let mut v: Vec<&formats::Impl> = cache
+            .impls
+            .get(&did)
+            .map(Vec::as_slice)
+            .unwrap_or(&[])
+            .iter()
+            .filter(|i| saw_impls.insert(i.def_id()))
+            .collect();
         if let TypeAliasItem(ait) = &*it.kind &&
             let aliased_clean_type = ait.item_type.as_ref().unwrap_or(&ait.type_) &&
             let Some(aliased_type_defid) = aliased_clean_type.def_id(cache) &&
@@ -181,13 +188,12 @@ impl SharedContext<'_> {
             v.extend(av.iter().filter(|impl_| {
                 if let Some(impl_def_id) = impl_.impl_item.item_id.as_def_id() {
                     reject_cx.types_may_unify(aliased_ty, tcx.type_of(impl_def_id).skip_binder())
+                        && saw_impls.insert(impl_def_id)
                 } else {
                     false
                 }
             }));
         }
-        let mut saw_impls = FxHashSet::default();
-        v.retain(|i| saw_impls.insert(i.def_id()));
         v
     }
 }