mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 14:38:46 +00:00
add extra variant because no more than 3 bools
This commit is contained in:
parent
a3fea80a68
commit
9ac6125e1d
1 changed files with 36 additions and 17 deletions
|
@ -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"];
|
||||
|
|
Loading…
Add table
Reference in a new issue