From 2e969c720b444420876a2b16cf10402553093a3c Mon Sep 17 00:00:00 2001 From: binarycat Date: Mon, 25 Aug 2025 10:06:16 -0500 Subject: [PATCH 1/2] rustdoc(opt): build_impl: check document_private earlier --- src/librustdoc/clean/inline.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 0d98c64bbde5f..8461e15c6c3f5 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -572,30 +572,30 @@ pub(crate) fn build_impl( super::build_deref_target_impls(cx, &trait_items, ret); } - // Return if the trait itself or any types of the generic parameters are doc(hidden). - let mut stack: Vec<&Type> = vec![&for_]; + if !document_hidden { + // Return if the trait itself or any types of the generic parameters are doc(hidden). + let mut stack: Vec<&Type> = vec![&for_]; - if let Some(did) = trait_.as_ref().map(|t| t.def_id()) - && !document_hidden - && tcx.is_doc_hidden(did) - { - return; - } - - if let Some(generics) = trait_.as_ref().and_then(|t| t.generics()) { - stack.extend(generics); - } - - while let Some(ty) = stack.pop() { - if let Some(did) = ty.def_id(&cx.cache) - && !document_hidden + if let Some(did) = trait_.as_ref().map(|t| t.def_id()) && tcx.is_doc_hidden(did) { return; } - if let Some(generics) = ty.generics() { + + if let Some(generics) = trait_.as_ref().and_then(|t| t.generics()) { stack.extend(generics); } + + while let Some(ty) = stack.pop() { + if let Some(did) = ty.def_id(&cx.cache) + && tcx.is_doc_hidden(did) + { + return; + } + if let Some(generics) = ty.generics() { + stack.extend(generics); + } + } } if let Some(did) = trait_.as_ref().map(|t| t.def_id()) { From f16d1fcb55d0b9c5d2a6c58e20c4352aa4a7c5fd Mon Sep 17 00:00:00 2001 From: binarycat Date: Mon, 25 Aug 2025 10:26:22 -0500 Subject: [PATCH 2/2] use size_hint in attrs_to_doc_fragments --- compiler/rustc_resolve/src/rustdoc.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_resolve/src/rustdoc.rs b/compiler/rustc_resolve/src/rustdoc.rs index 6450f63472ca9..f9f2f84bc50f6 100644 --- a/compiler/rustc_resolve/src/rustdoc.rs +++ b/compiler/rustc_resolve/src/rustdoc.rs @@ -207,8 +207,10 @@ pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>( attrs: impl Iterator)>, doc_only: bool, ) -> (Vec, ThinVec) { - let mut doc_fragments = Vec::new(); - let mut other_attrs = ThinVec::::new(); + let (min_size, max_size) = attrs.size_hint(); + let size_hint = max_size.unwrap_or(min_size); + let mut doc_fragments = Vec::with_capacity(size_hint); + let mut other_attrs = ThinVec::::with_capacity(if doc_only { 0 } else { size_hint }); for (attr, item_id) in attrs { if let Some((doc_str, comment_kind)) = attr.doc_str_and_comment_kind() { let doc = beautify_doc_string(doc_str, comment_kind); @@ -230,6 +232,9 @@ pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>( } } + doc_fragments.shrink_to_fit(); + other_attrs.shrink_to_fit(); + unindent_doc_fragments(&mut doc_fragments); (doc_fragments, other_attrs)