Skip to content

Commit 97440b5

Browse files
authored
Rollup merge of #100157 - rust-lang:notriddle/use-map-instead-of-repeated-push, r=Dylan-DPC
rustdoc: use `collect()` instead of repeatedly pushing
2 parents 721af40 + 70a6ae6 commit 97440b5

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/librustdoc/clean/mod.rs

+17-17
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,19 +1631,18 @@ 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

1643-
let mut bindings = vec![];
1644-
for pb in obj.projection_bounds() {
1645-
bindings.push(TypeBinding {
1643+
let bindings = obj
1644+
.projection_bounds()
1645+
.map(|pb| TypeBinding {
16461646
assoc: projection_to_path_segment(
16471647
pb.skip_binder()
16481648
.lift_to_tcx(cx.tcx)
@@ -1656,8 +1656,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
16561656
kind: TypeBindingKind::Equality {
16571657
term: clean_middle_term(pb.skip_binder().term, cx),
16581658
},
1659-
});
1660-
}
1659+
})
1660+
.collect();
16611661

16621662
let path = external_path(cx, did, false, bindings, substs);
16631663
bounds.insert(0, PolyTrait { trait_: path, generic_params: Vec::new() });

0 commit comments

Comments
 (0)