Skip to content

Commit 82bf232

Browse files
Move inherits_doc_hidden and should_ignore_res into clean/utils.rs
1 parent 31bb3c0 commit 82bf232

File tree

6 files changed

+38
-37
lines changed

6 files changed

+38
-37
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use thin_vec::ThinVec;
4141

4242
use crate::core::{self, DocContext, ImplTraitParam};
4343
use crate::formats::item_type::ItemType;
44-
use crate::visit_ast::{should_ignore_res, Module as DocModule};
44+
use crate::visit_ast::Module as DocModule;
4545

4646
use utils::*;
4747

src/librustdoc/clean/utils.rs

Lines changed: 33 additions & 1 deletion
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+
}

src/librustdoc/passes/check_doc_test_visibility.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
88
use super::Pass;
99
use crate::clean;
10+
use crate::clean::utils::inherits_doc_hidden;
1011
use crate::clean::*;
1112
use crate::core::DocContext;
1213
use crate::html::markdown::{find_testable_code, ErrorCodes, Ignore, LangString};
1314
use crate::visit::DocVisitor;
14-
use crate::visit_ast::inherits_doc_hidden;
1515
use rustc_hir as hir;
1616
use rustc_middle::lint::LintLevelSource;
1717
use rustc_session::lint;

src/librustdoc/passes/strip_hidden.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use rustc_span::symbol::sym;
66
use std::mem;
77

88
use crate::clean;
9+
use crate::clean::utils::inherits_doc_hidden;
910
use crate::clean::{Item, ItemIdSet};
1011
use crate::core::DocContext;
1112
use crate::fold::{strip_item, DocFolder};
1213
use crate::passes::{ImplStripper, Pass};
13-
use crate::visit_ast::inherits_doc_hidden;
1414

1515
pub(crate) const STRIP_HIDDEN: Pass = Pass {
1616
name: "strip-hidden",

src/librustdoc/passes/stripper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use rustc_hir::def_id::DefId;
33
use rustc_middle::ty::{TyCtxt, Visibility};
44
use std::mem;
55

6+
use crate::clean::utils::inherits_doc_hidden;
67
use crate::clean::{self, Item, ItemId, ItemIdSet};
78
use crate::fold::{strip_item, DocFolder};
89
use crate::formats::cache::Cache;
9-
use crate::visit_ast::inherits_doc_hidden;
1010
use crate::visit_lib::RustdocEffectiveVisibilities;
1111

1212
pub(crate) struct Stripper<'a, 'tcx> {

src/librustdoc/visit_ast.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_span::Span;
1616

1717
use std::mem;
1818

19+
use crate::clean::utils::{inherits_doc_hidden, should_ignore_res};
1920
use crate::clean::{cfg::Cfg, reexport_chain, AttributesExt, NestedAttributesExt};
2021
use crate::core;
2122

@@ -73,38 +74,6 @@ fn def_id_to_path(tcx: TyCtxt<'_>, did: DefId) -> Vec<Symbol> {
7374
std::iter::once(crate_name).chain(relative).collect()
7475
}
7576

76-
pub(crate) fn inherits_doc_hidden(
77-
tcx: TyCtxt<'_>,
78-
mut def_id: LocalDefId,
79-
stop_at: Option<LocalDefId>,
80-
) -> bool {
81-
let hir = tcx.hir();
82-
while let Some(id) = tcx.opt_local_parent(def_id) {
83-
if let Some(stop_at) = stop_at && id == stop_at {
84-
return false;
85-
}
86-
def_id = id;
87-
if tcx.is_doc_hidden(def_id.to_def_id()) {
88-
return true;
89-
} else if let Some(node) = hir.find_by_def_id(def_id) &&
90-
matches!(
91-
node,
92-
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(_), .. }),
93-
)
94-
{
95-
// `impl` blocks stand a bit on their own: unless they have `#[doc(hidden)]` directly
96-
// on them, they don't inherit it from the parent context.
97-
return false;
98-
}
99-
}
100-
false
101-
}
102-
103-
#[inline]
104-
pub(crate) fn should_ignore_res(res: Res) -> bool {
105-
matches!(res, Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..))
106-
}
107-
10877
pub(crate) struct RustdocVisitor<'a, 'tcx> {
10978
cx: &'a mut core::DocContext<'tcx>,
11079
view_item_stack: LocalDefIdSet,

0 commit comments

Comments
 (0)