diff options
| author | bors <bors@rust-lang.org> | 2020-12-22 00:20:14 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-12-22 00:20:14 +0000 |
| commit | 9310aff66c3a9d79c92f621c7f7ca3f87ea9f7de (patch) | |
| tree | 32d4a2cf63f1103efbb5a779f88d04dd26406a0e | |
| parent | 11c94a197726b6a981828cb1837d7c3eed1b841d (diff) | |
| parent | 01d7f87d8ee16915d8f663f44a5587ec45f54f76 (diff) | |
| download | rust-9310aff66c3a9d79c92f621c7f7ca3f87ea9f7de.tar.gz rust-9310aff66c3a9d79c92f621c7f7ca3f87ea9f7de.zip | |
Auto merge of #80208 - bugadani:generics-of-alloc, r=matthewjasper
Reserve necessary space for params in generics_of Always reserve space for the exact number of generic parameters we need in generics_of. As far as I can see, the default is 0/4 elements based on has_self, and the vector grows on after that.
| -rw-r--r-- | compiler/rustc_typeck/src/collect.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index d5643fcca87..bc6b2037c18 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -1369,7 +1369,11 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics { generics.parent_count + generics.params.len() }); - let mut params: Vec<_> = opt_self.into_iter().collect(); + let mut params: Vec<_> = Vec::with_capacity(ast_generics.params.len() + has_self as usize); + + if let Some(opt_self) = opt_self { + params.push(opt_self); + } let early_lifetimes = early_bound_lifetimes_from_generics(tcx, ast_generics); params.extend(early_lifetimes.enumerate().map(|(i, param)| ty::GenericParamDef { |
