about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-15 09:55:31 +0000
committerbors <bors@rust-lang.org>2023-09-15 09:55:31 +0000
commit56e1aaadb31542b32953292001be2312810e88fd (patch)
tree77011531d0e85e82528bde2a7aa73dd0e14ddbba
parent915c8af55006772590d491bea5ba329e357a553a (diff)
parent88f3f2315c1d215f4f91c021781588ead0de39f2 (diff)
downloadrust-56e1aaadb31542b32953292001be2312810e88fd.tar.gz
rust-56e1aaadb31542b32953292001be2312810e88fd.zip
Auto merge of #115851 - Alexendoo:clippy-doc-hidden-headers, r=flip1995
Ignore `#[doc(hidden)]` functions in clippy doc lints

Fixes https://github.com/rust-lang/rust-clippy/issues/11501

The implementation before #115689 had a check for unsugared doc comments that also happened to catch `#[doc(hidden)]`, this adds the check back in more explicitly

https://github.com/rust-lang/rust/blob/852bf4e51bf260550cd1a280d2146f1c0641b1e8/src/tools/clippy/clippy_lints/src/doc.rs#L526-L529

r? `@flip1995`
-rw-r--r--src/tools/clippy/clippy_lints/src/doc.rs4
-rw-r--r--src/tools/clippy/tests/ui/doc_errors.rs15
-rw-r--r--src/tools/clippy/tests/ui/doc_errors.stderr2
3 files changed, 20 insertions, 1 deletions
diff --git a/src/tools/clippy/clippy_lints/src/doc.rs b/src/tools/clippy/clippy_lints/src/doc.rs
index 4498e9ccdec..bf2add6aa64 100644
--- a/src/tools/clippy/clippy_lints/src/doc.rs
+++ b/src/tools/clippy/clippy_lints/src/doc.rs
@@ -479,6 +479,10 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
         Some(("fake".into(), "fake".into()))
     }
 
+    if is_doc_hidden(attrs) {
+        return None;
+    }
+
     let (fragments, _) = attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), true);
     let mut doc = String::new();
     for fragment in &fragments {
diff --git a/src/tools/clippy/tests/ui/doc_errors.rs b/src/tools/clippy/tests/ui/doc_errors.rs
index d661231c59e..9b3783aaf09 100644
--- a/src/tools/clippy/tests/ui/doc_errors.rs
+++ b/src/tools/clippy/tests/ui/doc_errors.rs
@@ -101,6 +101,11 @@ impl Struct1 {
     fn block_comment_leading_asterisks() -> Result<(), ()> {
         unimplemented!();
     }
+
+    #[doc(hidden)]
+    fn doc_hidden() -> Result<(), ()> {
+        unimplemented!();
+    }
 }
 
 pub trait Trait1 {
@@ -111,6 +116,11 @@ pub trait Trait1 {
     /// # Errors
     /// A description of the errors goes here.
     fn trait_method_with_errors_header() -> Result<(), ()>;
+
+    #[doc(hidden)]
+    fn doc_hidden() -> Result<(), ()> {
+        unimplemented!();
+    }
 }
 
 impl Trait1 for Struct1 {
@@ -123,6 +133,11 @@ impl Trait1 for Struct1 {
     }
 }
 
+#[doc(hidden)]
+pub trait DocHidden {
+    fn f() -> Result<(), ()>;
+}
+
 fn main() -> Result<(), ()> {
     Ok(())
 }
diff --git a/src/tools/clippy/tests/ui/doc_errors.stderr b/src/tools/clippy/tests/ui/doc_errors.stderr
index 28b2db2440b..dc59675b9e5 100644
--- a/src/tools/clippy/tests/ui/doc_errors.stderr
+++ b/src/tools/clippy/tests/ui/doc_errors.stderr
@@ -38,7 +38,7 @@ LL |     pub async fn async_pub_method_missing_errors_header() -> Result<(), ()>
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: docs for function returning `Result` missing `# Errors` section
-  --> $DIR/doc_errors.rs:108:5
+  --> $DIR/doc_errors.rs:113:5
    |
 LL |     fn trait_method_missing_errors_header() -> Result<(), ()>;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^