about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2022-08-04 18:13:53 -0700
committerMichael Howell <michael@notriddle.com>2022-08-04 18:13:53 -0700
commit70a6ae67090196d8b750809909d46fedb7754ff7 (patch)
treebe81de7141fc7fe51681b6f048f72566bb4b01b9
parent7ba51fa05b2e9406e753306c4dafe6bd34988310 (diff)
downloadrust-70a6ae67090196d8b750809909d46fedb7754ff7.tar.gz
rust-70a6ae67090196d8b750809909d46fedb7754ff7.zip
rustdoc: use `collect()` instead of repeatedly pushing to bounds
-rw-r--r--src/librustdoc/clean/mod.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 3e7e4c748ad..5e6f3070d0b 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1617,9 +1617,10 @@ pub(crate) fn clean_middle_ty<'tcx>(
             // HACK: pick the first `did` as the `did` of the trait object. Someone
             // might want to implement "native" support for marker-trait-only
             // trait objects.
-            let mut dids = obj.principal_def_id().into_iter().chain(obj.auto_traits());
-            let did = dids
-                .next()
+            let mut dids = obj.auto_traits();
+            let did = obj
+                .principal_def_id()
+                .or_else(|| dids.next())
                 .unwrap_or_else(|| panic!("found trait object `{:?}` with no traits?", this));
             let substs = match obj.principal() {
                 Some(principal) => principal.skip_binder().substs,
@@ -1630,15 +1631,14 @@ pub(crate) fn clean_middle_ty<'tcx>(
             inline::record_extern_fqn(cx, did, ItemType::Trait);
 
             let lifetime = clean_middle_region(*reg);
-            let mut bounds = vec![];
-
-            for did in dids {
-                let empty = cx.tcx.intern_substs(&[]);
-                let path = external_path(cx, did, false, vec![], empty);
-                inline::record_extern_fqn(cx, did, ItemType::Trait);
-                let bound = PolyTrait { trait_: path, generic_params: Vec::new() };
-                bounds.push(bound);
-            }
+            let mut bounds = dids
+                .map(|did| {
+                    let empty = cx.tcx.intern_substs(&[]);
+                    let path = external_path(cx, did, false, vec![], empty);
+                    inline::record_extern_fqn(cx, did, ItemType::Trait);
+                    PolyTrait { trait_: path, generic_params: Vec::new() }
+                })
+                .collect::<Vec<_>>();
 
             let bindings = obj
                 .projection_bounds()