diff options
| author | Lzu Tao <taolzu@gmail.com> | 2020-09-18 01:55:40 +0000 |
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2020-09-18 01:55:40 +0000 |
| commit | 2818032a2dee83b0b58318828e666e404838c8d9 (patch) | |
| tree | 0b4eb01e818f9eebc03d50d4322830bf92627d50 /src | |
| parent | f4e4485a052857e5dd32ea29ceb7b1a8223e83cc (diff) | |
| download | rust-2818032a2dee83b0b58318828e666e404838c8d9.tar.gz rust-2818032a2dee83b0b58318828e666e404838c8d9.zip | |
Calculate more correct capacity in merge_attrs
Co-authored-by: jyn514 <joshua@yottadb.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index f8987c6beca..a12181be67d 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -306,15 +306,17 @@ fn merge_attrs( attrs: Attrs<'_>, other_attrs: Option<Attrs<'_>>, ) -> clean::Attributes { - let mut merged_attrs: Vec<ast::Attribute> = Vec::with_capacity(attrs.len()); - // If we have additional attributes (from a re-export), + // NOTE: If we have additional attributes (from a re-export), // always insert them first. This ensure that re-export // doc comments show up before the original doc comments // when we render them. - if let Some(a) = other_attrs { - merged_attrs.extend(a.iter().cloned()); - } - merged_attrs.extend(attrs.to_vec()); + let merged_attrs = if let Some(inner) = other_attrs { + let mut both = inner.to_vec(); + both.extend_from_slice(attrs); + both + } else { + attrs.to_vec() + }; merged_attrs.clean(cx) } |
