about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlucarlig <luca.carlig@huawei.com>2024-02-25 17:16:07 +0400
committerlucarlig <luca.carlig@huawei.com>2024-02-25 17:16:07 +0400
commit9ac6125e1d034bdc84e9a8508fd96fa55cdf8209 (patch)
treefdfd11dcae39f3291f1c4cf7ade4f4f539501995
parenta3fea80a6826154a23eafe8e62f6b18cfae1dfbc (diff)
downloadrust-9ac6125e1d034bdc84e9a8508fd96fa55cdf8209.tar.gz
rust-9ac6125e1d034bdc84e9a8508fd96fa55cdf8209.zip
add extra variant because no more than 3 bools
-rw-r--r--clippy_lints/src/doc/mod.rs53
1 files changed, 36 insertions, 17 deletions
diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs
index be6748bdb7d..78d46928f35 100644
--- a/clippy_lints/src/doc/mod.rs
+++ b/clippy_lints/src/doc/mod.rs
@@ -400,11 +400,15 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
 
     fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
         let attrs = cx.tcx.hir().attrs(item.hir_id());
-        let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
+        let Some(DocInfo {
+            empty,
+            doc_headers: headers,
+        }) = check_attrs(cx, &self.valid_idents, attrs)
+        else {
             return;
         };
 
-        if headers.empty && !item.span.is_dummy() {
+        if empty && !item.span.is_dummy() {
             empty_docs::check(cx, attrs);
         }
 
@@ -455,7 +459,11 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
 
     fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
         let attrs = cx.tcx.hir().attrs(item.hir_id());
-        let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
+        let Some(DocInfo {
+            empty: _,
+            doc_headers: headers,
+        }) = check_attrs(cx, &self.valid_idents, attrs)
+        else {
             return;
         };
         if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
@@ -467,7 +475,11 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
 
     fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
         let attrs = cx.tcx.hir().attrs(item.hir_id());
-        let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
+        let Some(DocInfo {
+            empty: _,
+            doc_headers: headers,
+        }) = check_attrs(cx, &self.valid_idents, attrs)
+        else {
             return;
         };
         if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) {
@@ -507,7 +519,12 @@ struct DocHeaders {
     safety: bool,
     errors: bool,
     panics: bool,
+}
+
+#[derive(Copy, Clone, Default)]
+struct DocInfo {
     empty: bool,
+    doc_headers: DocHeaders,
 }
 
 /// Does some pre-processing on raw, desugared `#[doc]` attributes such as parsing them and
@@ -517,7 +534,7 @@ struct DocHeaders {
 /// Others are checked elsewhere, e.g. in `check_doc` if they need access to markdown, or
 /// back in the various late lint pass methods if they need the final doc headers, like "Safety" or
 /// "Panics" sections.
-fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[Attribute]) -> Option<DocHeaders> {
+fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[Attribute]) -> Option<DocInfo> {
     /// We don't want the parser to choke on intra doc links. Since we don't
     /// actually care about rendering them, just pretend that all broken links
     /// point to a fake address.
@@ -542,11 +559,10 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
         .trim()
         .to_string();
     doc.pop();
-
     if doc.is_empty() {
-        return Some(DocHeaders {
+        return Some(DocInfo {
             empty: true,
-            ..DocHeaders::default()
+            doc_headers: DocHeaders::default(),
         });
     }
 
@@ -556,15 +572,18 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
     let opts = main_body_opts() - Options::ENABLE_SMART_PUNCTUATION;
     let parser = pulldown_cmark::Parser::new_with_broken_link_callback(&doc, opts, Some(&mut cb));
 
-    Some(check_doc(
-        cx,
-        valid_idents,
-        parser.into_offset_iter(),
-        Fragments {
-            fragments: &fragments,
-            doc: &doc,
-        },
-    ))
+    Some(DocInfo {
+        empty: false,
+        doc_headers: check_doc(
+            cx,
+            valid_idents,
+            parser.into_offset_iter(),
+            Fragments {
+                fragments: &fragments,
+                doc: &doc,
+            },
+        ),
+    })
 }
 
 const RUST_CODE: &[&str] = &["rust", "no_run", "should_panic", "compile_fail"];