about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJ-ZhengLi <lizheng135@huawei.com>2024-03-12 10:40:40 +0800
committerJ-ZhengLi <lizheng135@huawei.com>2024-03-12 10:40:40 +0800
commit3cd6fd15a5b9f654b08d22949a21273d44ef64de (patch)
tree762a1be2ba66c52856b7dd2155f27c61dad1e6f6
parent10677d69015738e7c4434105c3077ea009d10980 (diff)
downloadrust-3cd6fd15a5b9f654b08d22949a21273d44ef64de.tar.gz
rust-3cd6fd15a5b9f654b08d22949a21273d44ef64de.zip
fix [`empty_docs`] trigger in proc-macro
-rw-r--r--clippy_lints/src/doc/mod.rs13
-rw-r--r--tests/ui/empty_docs.stderr20
2 files changed, 12 insertions, 21 deletions
diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs
index 003d26b7b89..b4087c43282 100644
--- a/clippy_lints/src/doc/mod.rs
+++ b/clippy_lints/src/doc/mod.rs
@@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxHashSet;
 use rustc_hir as hir;
 use rustc_hir::intravisit::{self, Visitor};
 use rustc_hir::{AnonConst, Expr};
-use rustc_lint::{LateContext, LateLintPass};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
 use rustc_middle::hir::nested_filter;
 use rustc_middle::lint::in_external_macro;
 use rustc_middle::ty;
@@ -538,7 +538,16 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
 
     suspicious_doc_comments::check(cx, attrs);
 
-    let (fragments, _) = attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), true);
+    let (fragments, _) = attrs_to_doc_fragments(
+        attrs.iter().filter_map(|attr| {
+            if in_external_macro(cx.sess(), attr.span) {
+                None
+            } else {
+                Some((attr, None))
+            }
+        }),
+        true,
+    );
     let mut doc = fragments.iter().fold(String::new(), |mut acc, fragment| {
         add_doc_fragment(&mut acc, fragment);
         acc
diff --git a/tests/ui/empty_docs.stderr b/tests/ui/empty_docs.stderr
index c6618ca3232..28ebea22c5d 100644
--- a/tests/ui/empty_docs.stderr
+++ b/tests/ui/empty_docs.stderr
@@ -73,23 +73,5 @@ LL |         ///
    |
    = help: consider removing or filling it
 
-error: empty doc comment
-  --> tests/ui/empty_docs.rs:77:5
-   |
-LL |     #[with_empty_docs]
-   |     ^^^^^^^^^^^^^^^^^^
-   |
-   = help: consider removing or filling it
-   = note: this error originates in the attribute macro `with_empty_docs` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: empty doc comment
-  --> tests/ui/empty_docs.rs:82:5
-   |
-LL |     #[with_empty_docs]
-   |     ^^^^^^^^^^^^^^^^^^
-   |
-   = help: consider removing or filling it
-   = note: this error originates in the attribute macro `with_empty_docs` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: aborting due to 11 previous errors
+error: aborting due to 9 previous errors