Skip to content

Commit fa94851

Browse files
authored
Rollup merge of #114129 - GuillaumeGomez:rustdoc-cleanup, r=notriddle
Rustdoc small cleanups Each commit does some little cleanups: * We had some `Res` comparisons in multiple places (and still do, but unless we use a macro, it's not possible to "merge" any further) so I moved it into a function. * It was weird to have some utils function used everywhere in `visit_ast` so I instead moved it into `clean/utils.rs`. * In HTML rendering, we had some write "issues": * Multiple calls that could be merged into one. * Some `write!` that could be `write_str`. * We didn't use the new `format!` args much. r? `@notriddle`
2 parents 32303b2 + b7871e5 commit fa94851

File tree

7 files changed

+123
-109
lines changed

7 files changed

+123
-109
lines changed

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2809,7 +2809,7 @@ fn clean_use_statement_inner<'tcx>(
28092809
cx: &mut DocContext<'tcx>,
28102810
inlined_names: &mut FxHashSet<(ItemType, Symbol)>,
28112811
) -> Vec<Item> {
2812-
if let Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) = path.res {
2812+
if should_ignore_res(path.res) {
28132813
return Vec::new();
28142814
}
28152815
// We need this comparison because some imports (for std types for example)

src/librustdoc/clean/utils.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast as ast;
1313
use rustc_ast::tokenstream::TokenTree;
1414
use rustc_hir as hir;
1515
use rustc_hir::def::{DefKind, Res};
16-
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
16+
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
1717
use rustc_middle::mir;
1818
use rustc_middle::mir::interpret::ConstValue;
1919
use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, TyCtxt};
@@ -629,3 +629,35 @@ pub(super) fn display_macro_source(
629629
}
630630
}
631631
}
632+
633+
pub(crate) fn inherits_doc_hidden(
634+
tcx: TyCtxt<'_>,
635+
mut def_id: LocalDefId,
636+
stop_at: Option<LocalDefId>,
637+
) -> bool {
638+
let hir = tcx.hir();
639+
while let Some(id) = tcx.opt_local_parent(def_id) {
640+
if let Some(stop_at) = stop_at && id == stop_at {
641+
return false;
642+
}
643+
def_id = id;
644+
if tcx.is_doc_hidden(def_id.to_def_id()) {
645+
return true;
646+
} else if let Some(node) = hir.find_by_def_id(def_id) &&
647+
matches!(
648+
node,
649+
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(_), .. }),
650+
)
651+
{
652+
// `impl` blocks stand a bit on their own: unless they have `#[doc(hidden)]` directly
653+
// on them, they don't inherit it from the parent context.
654+
return false;
655+
}
656+
}
657+
false
658+
}
659+
660+
#[inline]
661+
pub(crate) fn should_ignore_res(res: Res) -> bool {
662+
matches!(res, Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..))
663+
}

0 commit comments

Comments
 (0)