Separate missing_doc_code_examples
from intra-doc links
These two lints have no relation other than both being nightly-only. This allows stabilizing intra-doc links without stabilizing missing_doc_code_examples.
This commit is contained in:
parent
d6953df146
commit
617d10975e
4 changed files with 34 additions and 29 deletions
|
@ -23,7 +23,7 @@ use crate::clean::*;
|
||||||
use crate::core::DocContext;
|
use crate::core::DocContext;
|
||||||
use crate::fold::DocFolder;
|
use crate::fold::DocFolder;
|
||||||
use crate::html::markdown::markdown_links;
|
use crate::html::markdown::markdown_links;
|
||||||
use crate::passes::{look_for_tests, Pass};
|
use crate::passes::Pass;
|
||||||
|
|
||||||
use super::span_of_attrs;
|
use super::span_of_attrs;
|
||||||
|
|
||||||
|
@ -508,8 +508,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
|
||||||
let dox = item.attrs.collapsed_doc_value().unwrap_or_else(String::new);
|
let dox = item.attrs.collapsed_doc_value().unwrap_or_else(String::new);
|
||||||
trace!("got documentation '{}'", dox);
|
trace!("got documentation '{}'", dox);
|
||||||
|
|
||||||
look_for_tests(&cx, &dox, &item, true);
|
|
||||||
|
|
||||||
// find item's parent to resolve `Self` in item's docs below
|
// find item's parent to resolve `Self` in item's docs below
|
||||||
let parent_name = self.cx.as_local_hir_id(item.def_id).and_then(|item_hir| {
|
let parent_name = self.cx.as_local_hir_id(item.def_id).and_then(|item_hir| {
|
||||||
let parent_hir = self.cx.tcx.hir().get_parent_item(item_hir);
|
let parent_hir = self.cx.tcx.hir().get_parent_item(item_hir);
|
||||||
|
|
|
@ -312,12 +312,7 @@ impl DocFolder for ImportStripper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn look_for_tests<'tcx>(
|
pub fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
|
||||||
cx: &DocContext<'tcx>,
|
|
||||||
dox: &str,
|
|
||||||
item: &Item,
|
|
||||||
check_missing_code: bool,
|
|
||||||
) {
|
|
||||||
let hir_id = match cx.as_local_hir_id(item.def_id) {
|
let hir_id = match cx.as_local_hir_id(item.def_id) {
|
||||||
Some(hir_id) => hir_id,
|
Some(hir_id) => hir_id,
|
||||||
None => {
|
None => {
|
||||||
|
@ -340,12 +335,24 @@ pub fn look_for_tests<'tcx>(
|
||||||
|
|
||||||
find_testable_code(&dox, &mut tests, ErrorCodes::No, false, None);
|
find_testable_code(&dox, &mut tests, ErrorCodes::No, false, None);
|
||||||
|
|
||||||
if check_missing_code && tests.found_tests == 0 {
|
if tests.found_tests == 0 {
|
||||||
|
use clean::ItemEnum::*;
|
||||||
|
|
||||||
|
let should_report = match item.inner {
|
||||||
|
ExternCrateItem(_, _) | ImportItem(_) | PrimitiveItem(_) | KeywordItem(_) => false,
|
||||||
|
_ => true,
|
||||||
|
};
|
||||||
|
if should_report {
|
||||||
|
debug!("reporting error for {:?} (hir_id={:?})", item, hir_id);
|
||||||
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
|
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
|
||||||
cx.tcx.struct_span_lint_hir(lint::builtin::MISSING_DOC_CODE_EXAMPLES, hir_id, sp, |lint| {
|
cx.tcx.struct_span_lint_hir(
|
||||||
lint.build("missing code example in this documentation").emit()
|
lint::builtin::MISSING_DOC_CODE_EXAMPLES,
|
||||||
});
|
hir_id,
|
||||||
} else if !check_missing_code
|
sp,
|
||||||
|
|lint| lint.build("missing code example in this documentation").emit(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if rustc_feature::UnstableFeatures::from_environment().is_nightly_build()
|
||||||
&& tests.found_tests > 0
|
&& tests.found_tests > 0
|
||||||
&& !cx.renderinfo.borrow().access_levels.is_public(item.def_id)
|
&& !cx.renderinfo.borrow().access_levels.is_public(item.def_id)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,7 +30,7 @@ impl<'a, 'tcx> DocFolder for PrivateItemDocTestLinter<'a, 'tcx> {
|
||||||
let cx = self.cx;
|
let cx = self.cx;
|
||||||
let dox = item.attrs.collapsed_doc_value().unwrap_or_else(String::new);
|
let dox = item.attrs.collapsed_doc_value().unwrap_or_else(String::new);
|
||||||
|
|
||||||
look_for_tests(&cx, &dox, &item, false);
|
look_for_tests(&cx, &dox, &item);
|
||||||
|
|
||||||
self.fold_item_recur(item)
|
self.fold_item_recur(item)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,16 @@
|
||||||
|
error: missing code example in this documentation
|
||||||
|
--> $DIR/lint-group.rs:16:1
|
||||||
|
|
|
||||||
|
LL | /// wait, this doesn't have a doctest?
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/lint-group.rs:7:9
|
||||||
|
|
|
||||||
|
LL | #![deny(rustdoc)]
|
||||||
|
| ^^^^^^^
|
||||||
|
= note: `#[deny(missing_doc_code_examples)]` implied by `#[deny(rustdoc)]`
|
||||||
|
|
||||||
error: documentation test in private item
|
error: documentation test in private item
|
||||||
--> $DIR/lint-group.rs:19:1
|
--> $DIR/lint-group.rs:19:1
|
||||||
|
|
|
|
||||||
|
@ -29,18 +42,5 @@ LL | #![deny(rustdoc)]
|
||||||
= note: `#[deny(intra_doc_link_resolution_failure)]` implied by `#[deny(rustdoc)]`
|
= note: `#[deny(intra_doc_link_resolution_failure)]` implied by `#[deny(rustdoc)]`
|
||||||
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
||||||
|
|
||||||
error: missing code example in this documentation
|
|
||||||
--> $DIR/lint-group.rs:16:1
|
|
||||||
|
|
|
||||||
LL | /// wait, this doesn't have a doctest?
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
note: the lint level is defined here
|
|
||||||
--> $DIR/lint-group.rs:7:9
|
|
||||||
|
|
|
||||||
LL | #![deny(rustdoc)]
|
|
||||||
| ^^^^^^^
|
|
||||||
= note: `#[deny(missing_doc_code_examples)]` implied by `#[deny(rustdoc)]`
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue