Skip to content

Commit 617d109

Browse files
committed
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.
1 parent d6953df commit 617d109

File tree

4 files changed

+34
-29
lines changed

4 files changed

+34
-29
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::clean::*;
2323
use crate::core::DocContext;
2424
use crate::fold::DocFolder;
2525
use crate::html::markdown::markdown_links;
26-
use crate::passes::{look_for_tests, Pass};
26+
use crate::passes::Pass;
2727

2828
use super::span_of_attrs;
2929

@@ -508,8 +508,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
508508
let dox = item.attrs.collapsed_doc_value().unwrap_or_else(String::new);
509509
trace!("got documentation '{}'", dox);
510510

511-
look_for_tests(&cx, &dox, &item, true);
512-
513511
// find item's parent to resolve `Self` in item's docs below
514512
let parent_name = self.cx.as_local_hir_id(item.def_id).and_then(|item_hir| {
515513
let parent_hir = self.cx.tcx.hir().get_parent_item(item_hir);

src/librustdoc/passes/mod.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,7 @@ impl DocFolder for ImportStripper {
312312
}
313313
}
314314

315-
pub fn look_for_tests<'tcx>(
316-
cx: &DocContext<'tcx>,
317-
dox: &str,
318-
item: &Item,
319-
check_missing_code: bool,
320-
) {
315+
pub fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
321316
let hir_id = match cx.as_local_hir_id(item.def_id) {
322317
Some(hir_id) => hir_id,
323318
None => {
@@ -340,12 +335,24 @@ pub fn look_for_tests<'tcx>(
340335

341336
find_testable_code(&dox, &mut tests, ErrorCodes::No, false, None);
342337

343-
if check_missing_code && tests.found_tests == 0 {
344-
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
345-
cx.tcx.struct_span_lint_hir(lint::builtin::MISSING_DOC_CODE_EXAMPLES, hir_id, sp, |lint| {
346-
lint.build("missing code example in this documentation").emit()
347-
});
348-
} else if !check_missing_code
338+
if tests.found_tests == 0 {
339+
use clean::ItemEnum::*;
340+
341+
let should_report = match item.inner {
342+
ExternCrateItem(_, _) | ImportItem(_) | PrimitiveItem(_) | KeywordItem(_) => false,
343+
_ => true,
344+
};
345+
if should_report {
346+
debug!("reporting error for {:?} (hir_id={:?})", item, hir_id);
347+
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
348+
cx.tcx.struct_span_lint_hir(
349+
lint::builtin::MISSING_DOC_CODE_EXAMPLES,
350+
hir_id,
351+
sp,
352+
|lint| lint.build("missing code example in this documentation").emit(),
353+
);
354+
}
355+
} else if rustc_feature::UnstableFeatures::from_environment().is_nightly_build()
349356
&& tests.found_tests > 0
350357
&& !cx.renderinfo.borrow().access_levels.is_public(item.def_id)
351358
{

src/librustdoc/passes/private_items_doc_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'a, 'tcx> DocFolder for PrivateItemDocTestLinter<'a, 'tcx> {
3030
let cx = self.cx;
3131
let dox = item.attrs.collapsed_doc_value().unwrap_or_else(String::new);
3232

33-
look_for_tests(&cx, &dox, &item, false);
33+
look_for_tests(&cx, &dox, &item);
3434

3535
self.fold_item_recur(item)
3636
}

src/test/rustdoc-ui/lint-group.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
error: missing code example in this documentation
2+
--> $DIR/lint-group.rs:16:1
3+
|
4+
LL | /// wait, this doesn't have a doctest?
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-group.rs:7:9
9+
|
10+
LL | #![deny(rustdoc)]
11+
| ^^^^^^^
12+
= note: `#[deny(missing_doc_code_examples)]` implied by `#[deny(rustdoc)]`
13+
114
error: documentation test in private item
215
--> $DIR/lint-group.rs:19:1
316
|
@@ -29,18 +42,5 @@ LL | #![deny(rustdoc)]
2942
= note: `#[deny(intra_doc_link_resolution_failure)]` implied by `#[deny(rustdoc)]`
3043
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
3144

32-
error: missing code example in this documentation
33-
--> $DIR/lint-group.rs:16:1
34-
|
35-
LL | /// wait, this doesn't have a doctest?
36-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37-
|
38-
note: the lint level is defined here
39-
--> $DIR/lint-group.rs:7:9
40-
|
41-
LL | #![deny(rustdoc)]
42-
| ^^^^^^^
43-
= note: `#[deny(missing_doc_code_examples)]` implied by `#[deny(rustdoc)]`
44-
4545
error: aborting due to 3 previous errors
4646

0 commit comments

Comments
 (0)