Skip to content

Commit d7ad85f

Browse files
committed
move the the check into check_atr function
1 parent f32e92c commit d7ad85f

File tree

2 files changed

+15
-43
lines changed

2 files changed

+15
-43
lines changed

clippy_lints/src/doc/empty_docs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use super::EMPTY_DOCS;
77
// TODO: Adjust the parameters as necessary
88
pub(super) fn check(cx: &LateContext<'_>, attrs: &[Attribute]) {
99
let doc_attrs: Vec<_> = attrs.iter().filter(|attr| attr.doc_str().is_some()).collect();
10-
1110
let span;
1211
if let Some(first) = doc_attrs.first()
1312
&& let Some(last) = doc_attrs.last()

clippy_lints/src/doc/mod.rs

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -401,18 +401,10 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
401401

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

412-
if empty && !item.span.is_dummy() {
413-
empty_docs::check(cx, attrs);
414-
}
415-
416408
match item.kind {
417409
hir::ItemKind::Fn(ref sig, _, body_id) => {
418410
if !(is_entrypoint_fn(cx, item.owner_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) {
@@ -460,11 +452,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
460452

461453
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
462454
let attrs = cx.tcx.hir().attrs(item.hir_id());
463-
let Some(DocInfo {
464-
empty: _,
465-
doc_headers: headers,
466-
}) = check_attrs(cx, &self.valid_idents, attrs)
467-
else {
455+
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
468456
return;
469457
};
470458
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
@@ -476,11 +464,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
476464

477465
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
478466
let attrs = cx.tcx.hir().attrs(item.hir_id());
479-
let Some(DocInfo {
480-
empty: _,
481-
doc_headers: headers,
482-
}) = check_attrs(cx, &self.valid_idents, attrs)
483-
else {
467+
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
484468
return;
485469
};
486470
if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) {
@@ -522,20 +506,14 @@ struct DocHeaders {
522506
panics: bool,
523507
}
524508

525-
#[derive(Copy, Clone, Default)]
526-
struct DocInfo {
527-
empty: bool,
528-
doc_headers: DocHeaders,
529-
}
530-
531509
/// Does some pre-processing on raw, desugared `#[doc]` attributes such as parsing them and
532510
/// then delegates to `check_doc`.
533511
/// Some lints are already checked here if they can work with attributes directly and don't need
534512
/// to work with markdown.
535513
/// Others are checked elsewhere, e.g. in `check_doc` if they need access to markdown, or
536514
/// back in the various late lint pass methods if they need the final doc headers, like "Safety" or
537515
/// "Panics" sections.
538-
fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[Attribute]) -> Option<DocInfo> {
516+
fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[Attribute]) -> Option<DocHeaders> {
539517
/// We don't want the parser to choke on intra doc links. Since we don't
540518
/// actually care about rendering them, just pretend that all broken links
541519
/// point to a fake address.
@@ -558,10 +536,8 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
558536
doc.pop();
559537

560538
if doc.trim().is_empty() {
561-
return Some(DocInfo {
562-
empty: true,
563-
doc_headers: DocHeaders::default(),
564-
});
539+
empty_docs::check(cx, attrs);
540+
return Some(DocHeaders::default());
565541
}
566542

567543
let mut cb = fake_broken_link_callback;
@@ -570,18 +546,15 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
570546
let opts = main_body_opts() - Options::ENABLE_SMART_PUNCTUATION;
571547
let parser = pulldown_cmark::Parser::new_with_broken_link_callback(&doc, opts, Some(&mut cb));
572548

573-
Some(DocInfo {
574-
empty: false,
575-
doc_headers: check_doc(
576-
cx,
577-
valid_idents,
578-
parser.into_offset_iter(),
579-
Fragments {
580-
fragments: &fragments,
581-
doc: &doc,
582-
},
583-
),
584-
})
549+
Some(check_doc(
550+
cx,
551+
valid_idents,
552+
parser.into_offset_iter(),
553+
Fragments {
554+
fragments: &fragments,
555+
doc: &doc,
556+
},
557+
))
585558
}
586559

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

0 commit comments

Comments
 (0)