Improve lint level handling

This commit is contained in:
Guillaume Gomez 2020-10-12 13:48:45 +02:00
parent 22465b35a6
commit 5d20e1aa03
2 changed files with 4 additions and 2 deletions

View File

@ -254,8 +254,10 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> {
let has_doc_example = tests.found_tests != 0;
let hir_id = self.ctx.tcx.hir().local_def_id_to_hir_id(i.def_id.expect_local());
let (level, source) = self.ctx.tcx.lint_level_at_node(MISSING_DOCS, hir_id);
// `missing_docs` is allow-by-default, so don't treat this as ignoring the item
// unless the user had an explicit `allow`
let should_have_docs =
level != lint::Level::Allow || !matches!(source, LintSource::Node(..));
level != lint::Level::Allow || matches!(source, LintSource::Default);
debug!("counting {:?} {:?} in {}", i.type_(), i.name, i.source.filename);
self.items.entry(i.source.filename.clone()).or_default().count_item(
has_docs,

View File

@ -76,7 +76,7 @@ pub fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> bool
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_local());
let (level, source) =
cx.tcx.lint_level_at_node(lint::builtin::MISSING_DOC_CODE_EXAMPLES, hir_id);
level != lint::Level::Allow || !matches!(source, LintSource::Node(..))
level != lint::Level::Allow || matches!(source, LintSource::Default)
}
pub fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {