From 862211d540fe54deb46daa661716cb06a74151f8 Mon Sep 17 00:00:00 2001 From: Florian Nagel Date: Fri, 25 Feb 2022 14:36:23 +0100 Subject: [PATCH] Disable ``[`new-without-default`]`` for new() methods that are marked with '#[doc(hidden)]' Fixes issue #8152 --- clippy_lints/src/new_without_default.rs | 4 ++++ tests/ui/new_without_default.rs | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 47121ad84f2..b40425bb635 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -85,6 +85,10 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { // can't be implemented for unsafe new return; } + if clippy_utils::is_doc_hidden(cx.tcx.hir().attrs(id)) { + // shouldn't be implemented when it is hidden in docs + return; + } if impl_item .generics .params diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index c76e3b42438..e94f99c95f4 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -201,4 +201,14 @@ pub fn new() -> Self { } } +// see issue #8152 +// This should not create any lints +pub struct DocHidden; +impl DocHidden { + #[doc(hidden)] + pub fn new() -> Self { + DocHidden + } +} + fn main() {}