Skip to content

Commit 186f139

Browse files
Move visibility check inside the should_have_doc_example function
1 parent 91095b1 commit 186f139

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

src/librustdoc/passes/doc_test_lints.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,22 @@ impl crate::doctest::Tester for Tests {
5353
}
5454

5555
crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> bool {
56-
if matches!(
57-
*item.kind,
58-
clean::StructFieldItem(_)
59-
| clean::VariantItem(_)
60-
| clean::AssocConstItem(_, _)
61-
| clean::AssocTypeItem(_, _)
62-
| clean::TypedefItem(_, _)
63-
| clean::StaticItem(_)
64-
| clean::ConstantItem(_)
65-
| clean::ExternCrateItem(_, _)
66-
| clean::ImportItem(_)
67-
| clean::PrimitiveItem(_)
68-
| clean::KeywordItem(_)
69-
) {
56+
if !cx.renderinfo.borrow().access_levels.is_public(item.def_id)
57+
|| matches!(
58+
*item.kind,
59+
clean::StructFieldItem(_)
60+
| clean::VariantItem(_)
61+
| clean::AssocConstItem(_, _)
62+
| clean::AssocTypeItem(_, _)
63+
| clean::TypedefItem(_, _)
64+
| clean::StaticItem(_)
65+
| clean::ConstantItem(_)
66+
| clean::ExternCrateItem(_, _)
67+
| clean::ImportItem(_)
68+
| clean::PrimitiveItem(_)
69+
| clean::KeywordItem(_)
70+
)
71+
{
7072
return false;
7173
}
7274
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_local());
@@ -93,9 +95,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
9395
find_testable_code(&dox, &mut tests, ErrorCodes::No, false, None);
9496

9597
if tests.found_tests == 0 && cx.tcx.sess.is_nightly_build() {
96-
if cx.renderinfo.borrow().access_levels.is_public(item.def_id)
97-
&& should_have_doc_example(cx, &item)
98-
{
98+
if should_have_doc_example(cx, &item) {
9999
debug!("reporting error for {:?} (hir_id={:?})", item, hir_id);
100100
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
101101
cx.tcx.struct_span_lint_hir(

src/librustdoc/visit_ast.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ crate fn inherits_doc_hidden(cx: &core::DocContext<'_>, mut node: hir::HirId) ->
3535
if cx.tcx.hir().attrs(node).lists(sym::doc).has_word(sym::hidden) {
3636
return true;
3737
}
38-
if node == hir::CRATE_HIR_ID {
39-
break;
40-
}
4138
}
4239
false
4340
}

0 commit comments

Comments
 (0)