move the the check into check_atr function
This commit is contained in:
parent
f32e92cdc9
commit
d7ad85f521
2 changed files with 15 additions and 43 deletions
|
@ -7,7 +7,6 @@ use super::EMPTY_DOCS;
|
||||||
// TODO: Adjust the parameters as necessary
|
// TODO: Adjust the parameters as necessary
|
||||||
pub(super) fn check(cx: &LateContext<'_>, attrs: &[Attribute]) {
|
pub(super) fn check(cx: &LateContext<'_>, attrs: &[Attribute]) {
|
||||||
let doc_attrs: Vec<_> = attrs.iter().filter(|attr| attr.doc_str().is_some()).collect();
|
let doc_attrs: Vec<_> = attrs.iter().filter(|attr| attr.doc_str().is_some()).collect();
|
||||||
|
|
||||||
let span;
|
let span;
|
||||||
if let Some(first) = doc_attrs.first()
|
if let Some(first) = doc_attrs.first()
|
||||||
&& let Some(last) = doc_attrs.last()
|
&& let Some(last) = doc_attrs.last()
|
||||||
|
|
|
@ -401,18 +401,10 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||||
let Some(DocInfo {
|
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
|
||||||
empty,
|
|
||||||
doc_headers: headers,
|
|
||||||
}) = check_attrs(cx, &self.valid_idents, attrs)
|
|
||||||
else {
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if empty && !item.span.is_dummy() {
|
|
||||||
empty_docs::check(cx, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
match item.kind {
|
match item.kind {
|
||||||
hir::ItemKind::Fn(ref sig, _, body_id) => {
|
hir::ItemKind::Fn(ref sig, _, body_id) => {
|
||||||
if !(is_entrypoint_fn(cx, item.owner_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) {
|
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 {
|
||||||
|
|
||||||
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
|
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
|
||||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||||
let Some(DocInfo {
|
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
|
||||||
empty: _,
|
|
||||||
doc_headers: headers,
|
|
||||||
}) = check_attrs(cx, &self.valid_idents, attrs)
|
|
||||||
else {
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
|
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
|
||||||
|
@ -476,11 +464,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
|
||||||
|
|
||||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
|
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
|
||||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||||
let Some(DocInfo {
|
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
|
||||||
empty: _,
|
|
||||||
doc_headers: headers,
|
|
||||||
}) = check_attrs(cx, &self.valid_idents, attrs)
|
|
||||||
else {
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) {
|
if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) {
|
||||||
|
@ -522,12 +506,6 @@ struct DocHeaders {
|
||||||
panics: 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
|
/// Does some pre-processing on raw, desugared `#[doc]` attributes such as parsing them and
|
||||||
/// then delegates to `check_doc`.
|
/// then delegates to `check_doc`.
|
||||||
/// Some lints are already checked here if they can work with attributes directly and don't need
|
/// Some lints are already checked here if they can work with attributes directly and don't need
|
||||||
|
@ -535,7 +513,7 @@ struct DocInfo {
|
||||||
/// Others are checked elsewhere, e.g. in `check_doc` if they need access to markdown, or
|
/// 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
|
/// back in the various late lint pass methods if they need the final doc headers, like "Safety" or
|
||||||
/// "Panics" sections.
|
/// "Panics" sections.
|
||||||
fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[Attribute]) -> Option<DocInfo> {
|
fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[Attribute]) -> Option<DocHeaders> {
|
||||||
/// We don't want the parser to choke on intra doc links. Since we don't
|
/// 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
|
/// actually care about rendering them, just pretend that all broken links
|
||||||
/// point to a fake address.
|
/// point to a fake address.
|
||||||
|
@ -558,10 +536,8 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
|
||||||
doc.pop();
|
doc.pop();
|
||||||
|
|
||||||
if doc.trim().is_empty() {
|
if doc.trim().is_empty() {
|
||||||
return Some(DocInfo {
|
empty_docs::check(cx, attrs);
|
||||||
empty: true,
|
return Some(DocHeaders::default());
|
||||||
doc_headers: DocHeaders::default(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cb = fake_broken_link_callback;
|
let mut cb = fake_broken_link_callback;
|
||||||
|
@ -570,18 +546,15 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
|
||||||
let opts = main_body_opts() - Options::ENABLE_SMART_PUNCTUATION;
|
let opts = main_body_opts() - Options::ENABLE_SMART_PUNCTUATION;
|
||||||
let parser = pulldown_cmark::Parser::new_with_broken_link_callback(&doc, opts, Some(&mut cb));
|
let parser = pulldown_cmark::Parser::new_with_broken_link_callback(&doc, opts, Some(&mut cb));
|
||||||
|
|
||||||
Some(DocInfo {
|
Some(check_doc(
|
||||||
empty: false,
|
cx,
|
||||||
doc_headers: check_doc(
|
valid_idents,
|
||||||
cx,
|
parser.into_offset_iter(),
|
||||||
valid_idents,
|
Fragments {
|
||||||
parser.into_offset_iter(),
|
fragments: &fragments,
|
||||||
Fragments {
|
doc: &doc,
|
||||||
fragments: &fragments,
|
},
|
||||||
doc: &doc,
|
))
|
||||||
},
|
|
||||||
),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const RUST_CODE: &[&str] = &["rust", "no_run", "should_panic", "compile_fail"];
|
const RUST_CODE: &[&str] = &["rust", "no_run", "should_panic", "compile_fail"];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue