diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-08-05 21:54:34 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-05 21:54:34 +0530 |
| commit | 97440b5899d2ff5376afff33396d67abc132dd2b (patch) | |
| tree | 63813fadba6fd1f5f22d4a7fb91716ba16bedcf1 /src | |
| parent | 721af40dcbde949c7334295eccbbae2b120ab3e8 (diff) | |
| parent | 70a6ae67090196d8b750809909d46fedb7754ff7 (diff) | |
| download | rust-97440b5899d2ff5376afff33396d67abc132dd2b.tar.gz rust-97440b5899d2ff5376afff33396d67abc132dd2b.zip | |
Rollup merge of #100157 - rust-lang:notriddle/use-map-instead-of-repeated-push, r=Dylan-DPC
rustdoc: use `collect()` instead of repeatedly pushing
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 790727c918a..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,19 +1631,18 @@ 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 mut bindings = vec![]; - for pb in obj.projection_bounds() { - bindings.push(TypeBinding { + let bindings = obj + .projection_bounds() + .map(|pb| TypeBinding { assoc: projection_to_path_segment( pb.skip_binder() .lift_to_tcx(cx.tcx) @@ -1656,8 +1656,8 @@ pub(crate) fn clean_middle_ty<'tcx>( kind: TypeBindingKind::Equality { term: clean_middle_term(pb.skip_binder().term, cx), }, - }); - } + }) + .collect(); let path = external_path(cx, did, false, bindings, substs); bounds.insert(0, PolyTrait { trait_: path, generic_params: Vec::new() }); |
