From 186f13914a825039081795d382eb75c6a9f981ae Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 15 Feb 2021 14:17:43 +0100 Subject: [PATCH] Move visibility check inside the should_have_doc_example function --- src/librustdoc/passes/doc_test_lints.rs | 34 ++++++++++++------------- src/librustdoc/visit_ast.rs | 3 --- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/librustdoc/passes/doc_test_lints.rs b/src/librustdoc/passes/doc_test_lints.rs index 19815c7cd5f..cf8966fadf6 100644 --- a/src/librustdoc/passes/doc_test_lints.rs +++ b/src/librustdoc/passes/doc_test_lints.rs @@ -53,20 +53,22 @@ fn add_test(&mut self, _: String, config: LangString, _: usize) { } crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> bool { - if matches!( - *item.kind, - clean::StructFieldItem(_) - | clean::VariantItem(_) - | clean::AssocConstItem(_, _) - | clean::AssocTypeItem(_, _) - | clean::TypedefItem(_, _) - | clean::StaticItem(_) - | clean::ConstantItem(_) - | clean::ExternCrateItem(_, _) - | clean::ImportItem(_) - | clean::PrimitiveItem(_) - | clean::KeywordItem(_) - ) { + if !cx.renderinfo.borrow().access_levels.is_public(item.def_id) + || matches!( + *item.kind, + clean::StructFieldItem(_) + | clean::VariantItem(_) + | clean::AssocConstItem(_, _) + | clean::AssocTypeItem(_, _) + | clean::TypedefItem(_, _) + | clean::StaticItem(_) + | clean::ConstantItem(_) + | clean::ExternCrateItem(_, _) + | clean::ImportItem(_) + | clean::PrimitiveItem(_) + | clean::KeywordItem(_) + ) + { return false; } let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_local()); @@ -93,9 +95,7 @@ fn add_test(&mut self, _: String, config: LangString, _: usize) { find_testable_code(&dox, &mut tests, ErrorCodes::No, false, None); if tests.found_tests == 0 && cx.tcx.sess.is_nightly_build() { - if cx.renderinfo.borrow().access_levels.is_public(item.def_id) - && should_have_doc_example(cx, &item) - { + if should_have_doc_example(cx, &item) { debug!("reporting error for {:?} (hir_id={:?})", item, hir_id); let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span()); cx.tcx.struct_span_lint_hir( diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index b9b2be1db80..875be028e84 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -35,9 +35,6 @@ fn def_id_to_path(tcx: TyCtxt<'_>, did: DefId) -> Vec { if cx.tcx.hir().attrs(node).lists(sym::doc).has_word(sym::hidden) { return true; } - if node == hir::CRATE_HIR_ID { - break; - } } false }