Skip to content

Commit 2818032

Browse files
tesujijyn514
and
jyn514
committed
Calculate more correct capacity in merge_attrs
Co-authored-by: jyn514 <[email protected]>
1 parent f4e4485 commit 2818032

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/librustdoc/clean/inline.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,17 @@ fn merge_attrs(
306306
attrs: Attrs<'_>,
307307
other_attrs: Option<Attrs<'_>>,
308308
) -> clean::Attributes {
309-
let mut merged_attrs: Vec<ast::Attribute> = Vec::with_capacity(attrs.len());
310-
// If we have additional attributes (from a re-export),
309+
// NOTE: If we have additional attributes (from a re-export),
311310
// always insert them first. This ensure that re-export
312311
// doc comments show up before the original doc comments
313312
// when we render them.
314-
if let Some(a) = other_attrs {
315-
merged_attrs.extend(a.iter().cloned());
316-
}
317-
merged_attrs.extend(attrs.to_vec());
313+
let merged_attrs = if let Some(inner) = other_attrs {
314+
let mut both = inner.to_vec();
315+
both.extend_from_slice(attrs);
316+
both
317+
} else {
318+
attrs.to_vec()
319+
};
318320
merged_attrs.clean(cx)
319321
}
320322

0 commit comments

Comments
 (0)