replace some adhoc logic with article_and_descr
This commit is contained in:
parent
38114ff16e
commit
2daaf2b252
1 changed files with 26 additions and 19 deletions
|
@ -349,7 +349,7 @@ impl MissingDoc {
|
||||||
id: Option<hir::HirId>,
|
id: Option<hir::HirId>,
|
||||||
attrs: &[ast::Attribute],
|
attrs: &[ast::Attribute],
|
||||||
sp: Span,
|
sp: Span,
|
||||||
desc: &'static str,
|
desc: &str,
|
||||||
) {
|
) {
|
||||||
// If we're building a test harness, then warning about
|
// If we're building a test harness, then warning about
|
||||||
// documentation is probably not really relevant right now.
|
// documentation is probably not really relevant right now.
|
||||||
|
@ -413,12 +413,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
|
||||||
let desc = match it.kind {
|
match it.kind {
|
||||||
hir::ItemKind::Fn(..) => "a function",
|
|
||||||
hir::ItemKind::Mod(..) => "a module",
|
|
||||||
hir::ItemKind::Enum(..) => "an enum",
|
|
||||||
hir::ItemKind::Struct(..) => "a struct",
|
|
||||||
hir::ItemKind::Union(..) => "a union",
|
|
||||||
hir::ItemKind::Trait(.., trait_item_refs) => {
|
hir::ItemKind::Trait(.., trait_item_refs) => {
|
||||||
// Issue #11592: traits are always considered exported, even when private.
|
// Issue #11592: traits are always considered exported, even when private.
|
||||||
if let hir::VisibilityKind::Inherited = it.vis.node {
|
if let hir::VisibilityKind::Inherited = it.vis.node {
|
||||||
|
@ -428,33 +423,45 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
"a trait"
|
|
||||||
}
|
}
|
||||||
hir::ItemKind::TyAlias(..) => "a type alias",
|
|
||||||
hir::ItemKind::Impl { of_trait: Some(ref trait_ref), items, .. } => {
|
hir::ItemKind::Impl { of_trait: Some(ref trait_ref), items, .. } => {
|
||||||
// If the trait is private, add the impl items to `private_traits` so they don't get
|
// If the trait is private, add the impl items to `private_traits` so they don't get
|
||||||
// reported for missing docs.
|
// reported for missing docs.
|
||||||
let real_trait = trait_ref.path.res.def_id();
|
let real_trait = trait_ref.path.res.def_id();
|
||||||
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(real_trait) {
|
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(real_trait) {
|
||||||
match cx.tcx.hir().find(hir_id) {
|
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
|
||||||
Some(Node::Item(item)) => {
|
if let hir::VisibilityKind::Inherited = item.vis.node {
|
||||||
if let hir::VisibilityKind::Inherited = item.vis.node {
|
for impl_item_ref in items {
|
||||||
for impl_item_ref in items {
|
self.private_traits.insert(impl_item_ref.id.hir_id);
|
||||||
self.private_traits.insert(impl_item_ref.id.hir_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hir::ItemKind::Const(..) => "a constant",
|
|
||||||
hir::ItemKind::Static(..) => "a static",
|
hir::ItemKind::TyAlias(..)
|
||||||
|
| hir::ItemKind::Fn(..)
|
||||||
|
| hir::ItemKind::Mod(..)
|
||||||
|
| hir::ItemKind::Enum(..)
|
||||||
|
| hir::ItemKind::Struct(..)
|
||||||
|
| hir::ItemKind::Union(..)
|
||||||
|
| hir::ItemKind::Const(..)
|
||||||
|
| hir::ItemKind::Static(..) => {}
|
||||||
|
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.check_missing_docs_attrs(cx, Some(it.hir_id), &it.attrs, it.span, desc);
|
let def_id = cx.tcx.hir().local_def_id(it.hir_id);
|
||||||
|
let (article, desc) = cx.tcx.article_and_description(def_id);
|
||||||
|
|
||||||
|
self.check_missing_docs_attrs(
|
||||||
|
cx,
|
||||||
|
Some(it.hir_id),
|
||||||
|
&it.attrs,
|
||||||
|
it.span,
|
||||||
|
&format!("{} {}", article, desc),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, trait_item: &hir::TraitItem<'_>) {
|
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, trait_item: &hir::TraitItem<'_>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue