Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace some desc logic in librustc_lint with article_and_desc #69740

Merged
merged 5 commits into from
Mar 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ impl MissingDoc {
id: Option<hir::HirId>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anything pass None for this? If not you could remove the Option and compute article_and_desc inside here from the HirId.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it is passed with a Crate down below, so for now I will keep the option.

attrs: &[ast::Attribute],
sp: Span,
desc: &str,
article: &'static str,
desc: &'static str,
) {
// If we're building a test harness, then warning about
// documentation is probably not really relevant right now.
Expand All @@ -374,7 +375,7 @@ impl MissingDoc {
let has_doc = attrs.iter().any(|a| has_doc(a));
if !has_doc {
cx.struct_span_lint(MISSING_DOCS, cx.tcx.sess.source_map().def_span(sp), |lint| {
lint.build(&format!("missing documentation for {}", desc)).emit()
lint.build(&format!("missing documentation for {} {}", article, desc)).emit()
});
}
}
Expand All @@ -398,7 +399,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
}

fn check_crate(&mut self, cx: &LateContext<'_, '_>, krate: &hir::Crate<'_>) {
self.check_missing_docs_attrs(cx, None, &krate.item.attrs, krate.item.span, "crate");
self.check_missing_docs_attrs(cx, None, &krate.item.attrs, krate.item.span, "a", "crate");

for macro_def in krate.exported_macros {
let has_doc = macro_def.attrs.iter().any(|a| has_doc(a));
Expand Down Expand Up @@ -455,13 +456,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
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),
);
self.check_missing_docs_attrs(cx, Some(it.hir_id), &it.attrs, it.span, article, desc);
}

fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, trait_item: &hir::TraitItem<'_>) {
Expand All @@ -477,7 +472,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
Some(trait_item.hir_id),
&trait_item.attrs,
trait_item.span,
&format!("{} {}", article, desc),
article,
desc,
);
}

Expand All @@ -494,18 +490,26 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
Some(impl_item.hir_id),
&impl_item.attrs,
impl_item.span,
&format!("{} {}", article, desc),
article,
desc,
);
}

fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, sf: &hir::StructField<'_>) {
if !sf.is_positional() {
self.check_missing_docs_attrs(cx, Some(sf.hir_id), &sf.attrs, sf.span, "a struct field")
self.check_missing_docs_attrs(
cx,
Some(sf.hir_id),
&sf.attrs,
sf.span,
"a",
"struct field",
)
}
}

fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant<'_>) {
self.check_missing_docs_attrs(cx, Some(v.id), &v.attrs, v.span, "a variant");
self.check_missing_docs_attrs(cx, Some(v.id), &v.attrs, v.span, "a", "variant");
}
}

Expand Down