diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-10-18 08:13:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-18 08:13:28 +0200 |
| commit | cd72393566b473121cb6e525a04c3b022b18bc5b (patch) | |
| tree | 4242c2bb92be44f2b5ef3f35adeb2288a4670f0c | |
| parent | 5898c5d88e7a7b7a28ab8fcca360c868b7f65d20 (diff) | |
| parent | d39a1bec81f672f7bb270023f2eb91a51a22d319 (diff) | |
| download | rust-cd72393566b473121cb6e525a04c3b022b18bc5b.tar.gz rust-cd72393566b473121cb6e525a04c3b022b18bc5b.zip | |
Rollup merge of #89987 - pierwill:fix-85526-docs-hidden-assoc, r=GuillaumeGomez
Check implementing type for `#[doc(hidden)]` Closes #85526.
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/hidden-doc-associated-item.rs | 15 |
2 files changed, 33 insertions, 0 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 57c1c8f3ecb..c228ecb03fd 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -657,6 +657,24 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { return; } + // If the method is an impl for an item with docs_hidden, don't doc. + if method_context(cx, impl_item.hir_id()) == MethodLateContext::PlainImpl { + let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id()); + let impl_ty = cx.tcx.type_of(parent); + let outerdef = match impl_ty.kind() { + ty::Adt(def, _) => Some(def.did), + ty::Foreign(def_id) => Some(*def_id), + _ => None, + }; + let is_hidden = match outerdef { + Some(id) => cx.tcx.is_doc_hidden(id), + None => false, + }; + if is_hidden { + return; + } + } + let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id()); self.check_missing_docs_attrs(cx, impl_item.def_id, impl_item.span, article, desc); } diff --git a/src/test/ui/hidden-doc-associated-item.rs b/src/test/ui/hidden-doc-associated-item.rs new file mode 100644 index 00000000000..d431f9e899c --- /dev/null +++ b/src/test/ui/hidden-doc-associated-item.rs @@ -0,0 +1,15 @@ +// check-pass +// See issue #85526. +// This test should produce no warnings. + +#![deny(missing_docs)] +//! Crate docs + +#[doc(hidden)] +pub struct Foo; + +impl Foo { + pub fn bar() {} +} + +fn main() {} |
