about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2024-08-18 14:13:45 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2024-08-18 14:14:00 +0200
commita2033428c4ca9883a2b7cbbd1f167d481b0d240c (patch)
tree25495d9f5a7e26a53f89ce1ac1f8ce36eb2ae396
parent3c6e5ef4ae20c7439a2bc951ef349c59954412c6 (diff)
downloadrust-a2033428c4ca9883a2b7cbbd1f167d481b0d240c.tar.gz
rust-a2033428c4ca9883a2b7cbbd1f167d481b0d240c.zip
Do not emit `TOO_LONG_FIRST_DOC_PARAGRAPH` lint if item is generated from proc-macro and simplify code to emit lint
-rw-r--r--clippy_lints/src/doc/too_long_first_doc_paragraph.rs39
1 files changed, 18 insertions, 21 deletions
diff --git a/clippy_lints/src/doc/too_long_first_doc_paragraph.rs b/clippy_lints/src/doc/too_long_first_doc_paragraph.rs
index a47cba64b28..7bb3bb12f2c 100644
--- a/clippy_lints/src/doc/too_long_first_doc_paragraph.rs
+++ b/clippy_lints/src/doc/too_long_first_doc_paragraph.rs
@@ -3,7 +3,8 @@ use rustc_errors::Applicability;
 use rustc_hir::{Item, ItemKind};
 use rustc_lint::LateContext;
 
-use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
+use clippy_utils::diagnostics::span_lint_and_then;
+use clippy_utils::is_from_proc_macro;
 use clippy_utils::source::snippet_opt;
 
 use super::TOO_LONG_FIRST_DOC_PARAGRAPH;
@@ -63,32 +64,28 @@ pub(super) fn check(
     let &[first_span, .., last_span] = spans.as_slice() else {
         return;
     };
+    if is_from_proc_macro(cx, item) {
+        return;
+    }
 
-    if should_suggest_empty_doc
-        && let Some(second_span) = spans.get(1)
-        && let new_span = first_span.with_hi(second_span.lo()).with_lo(first_span.hi())
-        && let Some(snippet) = snippet_opt(cx, new_span)
-    {
-        span_lint_and_then(
-            cx,
-            TOO_LONG_FIRST_DOC_PARAGRAPH,
-            first_span.with_hi(last_span.lo()),
-            "first doc comment paragraph is too long",
-            |diag| {
+    span_lint_and_then(
+        cx,
+        TOO_LONG_FIRST_DOC_PARAGRAPH,
+        first_span.with_hi(last_span.lo()),
+        "first doc comment paragraph is too long",
+        |diag| {
+            if should_suggest_empty_doc
+                && let Some(second_span) = spans.get(1)
+                && let new_span = first_span.with_hi(second_span.lo()).with_lo(first_span.hi())
+                && let Some(snippet) = snippet_opt(cx, new_span)
+            {
                 diag.span_suggestion(
                     new_span,
                     "add an empty line",
                     format!("{snippet}///\n"),
                     Applicability::MachineApplicable,
                 );
-            },
-        );
-        return;
-    }
-    span_lint(
-        cx,
-        TOO_LONG_FIRST_DOC_PARAGRAPH,
-        first_span.with_hi(last_span.lo()),
-        "first doc comment paragraph is too long",
+            }
+        },
     );
 }