Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9ac6125

Browse files
committed
add extra variant because no more than 3 bools
1 parent a3fea80 commit 9ac6125

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

clippy_lints/src/doc/mod.rs

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,15 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
400400

401401
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
402402
let attrs = cx.tcx.hir().attrs(item.hir_id());
403-
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
403+
let Some(DocInfo {
404+
empty,
405+
doc_headers: headers,
406+
}) = check_attrs(cx, &self.valid_idents, attrs)
407+
else {
404408
return;
405409
};
406410

407-
if headers.empty && !item.span.is_dummy() {
411+
if empty && !item.span.is_dummy() {
408412
empty_docs::check(cx, attrs);
409413
}
410414

@@ -455,7 +459,11 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
455459

456460
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
457461
let attrs = cx.tcx.hir().attrs(item.hir_id());
458-
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
462+
let Some(DocInfo {
463+
empty: _,
464+
doc_headers: headers,
465+
}) = check_attrs(cx, &self.valid_idents, attrs)
466+
else {
459467
return;
460468
};
461469
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
@@ -467,7 +475,11 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
467475

468476
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
469477
let attrs = cx.tcx.hir().attrs(item.hir_id());
470-
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
478+
let Some(DocInfo {
479+
empty: _,
480+
doc_headers: headers,
481+
}) = check_attrs(cx, &self.valid_idents, attrs)
482+
else {
471483
return;
472484
};
473485
if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) {
@@ -507,7 +519,12 @@ struct DocHeaders {
507519
safety: bool,
508520
errors: bool,
509521
panics: bool,
522+
}
523+
524+
#[derive(Copy, Clone, Default)]
525+
struct DocInfo {
510526
empty: bool,
527+
doc_headers: DocHeaders,
511528
}
512529

513530
/// Does some pre-processing on raw, desugared `#[doc]` attributes such as parsing them and
@@ -517,7 +534,7 @@ struct DocHeaders {
517534
/// Others are checked elsewhere, e.g. in `check_doc` if they need access to markdown, or
518535
/// back in the various late lint pass methods if they need the final doc headers, like "Safety" or
519536
/// "Panics" sections.
520-
fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[Attribute]) -> Option<DocHeaders> {
537+
fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[Attribute]) -> Option<DocInfo> {
521538
/// We don't want the parser to choke on intra doc links. Since we don't
522539
/// actually care about rendering them, just pretend that all broken links
523540
/// point to a fake address.
@@ -542,11 +559,10 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
542559
.trim()
543560
.to_string();
544561
doc.pop();
545-
546562
if doc.is_empty() {
547-
return Some(DocHeaders {
563+
return Some(DocInfo {
548564
empty: true,
549-
..DocHeaders::default()
565+
doc_headers: DocHeaders::default(),
550566
});
551567
}
552568

@@ -556,15 +572,18 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
556572
let opts = main_body_opts() - Options::ENABLE_SMART_PUNCTUATION;
557573
let parser = pulldown_cmark::Parser::new_with_broken_link_callback(&doc, opts, Some(&mut cb));
558574

559-
Some(check_doc(
560-
cx,
561-
valid_idents,
562-
parser.into_offset_iter(),
563-
Fragments {
564-
fragments: &fragments,
565-
doc: &doc,
566-
},
567-
))
575+
Some(DocInfo {
576+
empty: false,
577+
doc_headers: check_doc(
578+
cx,
579+
valid_idents,
580+
parser.into_offset_iter(),
581+
Fragments {
582+
fragments: &fragments,
583+
doc: &doc,
584+
},
585+
),
586+
})
568587
}
569588

570589
const RUST_CODE: &[&str] = &["rust", "no_run", "should_panic", "compile_fail"];

0 commit comments

Comments
 (0)