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 47121ad84..b40425bb6 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -85,6 +85,10 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { // 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 c76e3b424..e94f99c95 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -201,4 +201,14 @@ pub mod issue7220 { } } +// see issue #8152 +// This should not create any lints +pub struct DocHidden; +impl DocHidden { + #[doc(hidden)] + pub fn new() -> Self { + DocHidden + } +} + fn main() {}