Skip to content

Commit 70a6ae6

Browse files
committed
rustdoc: use collect() instead of repeatedly pushing to bounds
1 parent 7ba51fa commit 70a6ae6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/librustdoc/clean/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1617,9 +1617,10 @@ pub(crate) fn clean_middle_ty<'tcx>(
16171617
// HACK: pick the first `did` as the `did` of the trait object. Someone
16181618
// might want to implement "native" support for marker-trait-only
16191619
// trait objects.
1620-
let mut dids = obj.principal_def_id().into_iter().chain(obj.auto_traits());
1621-
let did = dids
1622-
.next()
1620+
let mut dids = obj.auto_traits();
1621+
let did = obj
1622+
.principal_def_id()
1623+
.or_else(|| dids.next())
16231624
.unwrap_or_else(|| panic!("found trait object `{:?}` with no traits?", this));
16241625
let substs = match obj.principal() {
16251626
Some(principal) => principal.skip_binder().substs,
@@ -1630,15 +1631,14 @@ pub(crate) fn clean_middle_ty<'tcx>(
16301631
inline::record_extern_fqn(cx, did, ItemType::Trait);
16311632

16321633
let lifetime = clean_middle_region(*reg);
1633-
let mut bounds = vec![];
1634-
1635-
for did in dids {
1636-
let empty = cx.tcx.intern_substs(&[]);
1637-
let path = external_path(cx, did, false, vec![], empty);
1638-
inline::record_extern_fqn(cx, did, ItemType::Trait);
1639-
let bound = PolyTrait { trait_: path, generic_params: Vec::new() };
1640-
bounds.push(bound);
1641-
}
1634+
let mut bounds = dids
1635+
.map(|did| {
1636+
let empty = cx.tcx.intern_substs(&[]);
1637+
let path = external_path(cx, did, false, vec![], empty);
1638+
inline::record_extern_fqn(cx, did, ItemType::Trait);
1639+
PolyTrait { trait_: path, generic_params: Vec::new() }
1640+
})
1641+
.collect::<Vec<_>>();
16421642

16431643
let bindings = obj
16441644
.projection_bounds()

0 commit comments

Comments
 (0)