Rollup merge of #76716 - GuillaumeGomez:stop-complains-on-doc-hidden, r=jyn514
Don't warn for `missing_doc_examples` when item is #[doc(hidden)] r? `@jyn514`
This commit is contained in:
commit
95bbc7ef33
@ -9,8 +9,10 @@ use crate::clean::*;
|
||||
use crate::core::DocContext;
|
||||
use crate::fold::DocFolder;
|
||||
use crate::html::markdown::{find_testable_code, ErrorCodes, Ignore, LangString};
|
||||
use crate::visit_ast::inherits_doc_hidden;
|
||||
use rustc_middle::lint::LintLevelSource;
|
||||
use rustc_session::lint;
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
crate const CHECK_PRIVATE_ITEMS_DOC_TESTS: Pass = Pass {
|
||||
name: "check-private-items-doc-tests",
|
||||
@ -51,23 +53,30 @@ impl crate::doctest::Tester for Tests {
|
||||
}
|
||||
|
||||
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.cache.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());
|
||||
if cx.tcx.hir().attrs(hir_id).lists(sym::doc).has_word(sym::hidden)
|
||||
|| inherits_doc_hidden(cx.tcx, hir_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let (level, source) = cx.tcx.lint_level_at_node(crate::lint::MISSING_DOC_CODE_EXAMPLES, hir_id);
|
||||
level != lint::Level::Allow || matches!(source, LintLevelSource::Default)
|
||||
}
|
||||
|
@ -29,6 +29,16 @@ fn def_id_to_path(tcx: TyCtxt<'_>, did: DefId) -> Vec<String> {
|
||||
std::iter::once(crate_name).chain(relative).collect()
|
||||
}
|
||||
|
||||
crate fn inherits_doc_hidden(tcx: TyCtxt<'_>, mut node: hir::HirId) -> bool {
|
||||
while let Some(id) = tcx.hir().get_enclosing_scope(node) {
|
||||
node = id;
|
||||
if tcx.hir().attrs(node).lists(sym::doc).has_word(sym::hidden) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
// Also, is there some reason that this doesn't use the 'visit'
|
||||
// framework from syntax?.
|
||||
|
||||
@ -158,19 +168,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||
om: &mut Module<'tcx>,
|
||||
please_inline: bool,
|
||||
) -> bool {
|
||||
fn inherits_doc_hidden(cx: &core::DocContext<'_>, mut node: hir::HirId) -> bool {
|
||||
while let Some(id) = cx.tcx.hir().get_enclosing_scope(node) {
|
||||
node = id;
|
||||
if cx.tcx.hir().attrs(node).lists(sym::doc).has_word(sym::hidden) {
|
||||
return true;
|
||||
}
|
||||
if node == hir::CRATE_HIR_ID {
|
||||
break;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
debug!("maybe_inline_local res: {:?}", res);
|
||||
|
||||
let tcx = self.cx.tcx;
|
||||
@ -212,7 +209,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||
};
|
||||
|
||||
let is_private = !self.cx.cache.access_levels.is_public(res_did);
|
||||
let is_hidden = inherits_doc_hidden(self.cx, res_hir_id);
|
||||
let is_hidden = inherits_doc_hidden(self.cx.tcx, res_hir_id);
|
||||
|
||||
// Only inline if requested or if the item would otherwise be stripped.
|
||||
if (!please_inline && !is_private && !is_hidden) || is_no_inline {
|
||||
|
@ -12,16 +12,16 @@
|
||||
/// ```
|
||||
/// println!("hello");
|
||||
/// ```
|
||||
fn test() {
|
||||
pub fn test() {
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
mod module1 { //~ ERROR
|
||||
pub mod module1 { //~ ERROR
|
||||
}
|
||||
|
||||
#[allow(rustdoc::missing_doc_code_examples)]
|
||||
/// doc
|
||||
mod module2 {
|
||||
pub mod module2 {
|
||||
|
||||
/// doc
|
||||
pub fn test() {}
|
||||
@ -63,9 +63,22 @@ pub enum Enum {
|
||||
/// Doc
|
||||
//~^ ERROR
|
||||
#[repr(C)]
|
||||
union Union {
|
||||
pub union Union {
|
||||
/// Doc, but no code example and it's fine!
|
||||
a: i32,
|
||||
/// Doc, but no code example and it's fine!
|
||||
b: f32,
|
||||
}
|
||||
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod foo {
|
||||
pub fn bar() {}
|
||||
}
|
||||
|
||||
fn babar() {}
|
||||
|
||||
|
||||
mod fofoo {
|
||||
pub fn tadam() {}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
error: missing code example in this documentation
|
||||
--> $DIR/lint-missing-doc-code-example.rs:19:1
|
||||
|
|
||||
LL | / mod module1 {
|
||||
LL | / pub mod module1 {
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
|
Loading…
x
Reference in New Issue
Block a user