Skip to content

Commit 885a9f9

Browse files
committed
Migrate check_doc_test_visibility
1 parent 0dcccb7 commit 885a9f9

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

compiler/rustc_error_messages/locales/en-US/rustdoc.ftl

+6
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,9 @@ rustdoc_bare_url_not_hyperlink =
128128
this URL is not a hyperlink
129129
.note = bare URLs are not automatically turned into clickable links
130130
.suggestion = use an automatic link instead
131+
132+
rustdoc_missing_doc_code_examples =
133+
missing code example in this documentation
134+
135+
rustdoc_private_doc_tests =
136+
documentation test in private item

src/librustdoc/errors.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
33
use rustc_span::Span;
44

55
use std::io;
6-
use std::path::{Path, PathBuf};
6+
use std::path::Path;
77

88
#[derive(Diagnostic)]
99
#[diag(rustdoc_compilation_failed)]
@@ -248,3 +248,11 @@ pub struct BareUrlNotHyperlink<'a> {
248248
pub span: Span,
249249
pub url: &'a str,
250250
}
251+
252+
#[derive(LintDiagnostic)]
253+
#[diag(rustdoc_missing_doc_code_examples)]
254+
pub struct MissingDocCodeExamples;
255+
256+
#[derive(LintDiagnostic)]
257+
#[diag(rustdoc_private_doc_tests)]
258+
pub struct PrivateDocTests;

src/librustdoc/passes/check_doc_test_visibility.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use super::Pass;
99
use crate::clean;
1010
use crate::clean::*;
1111
use crate::core::DocContext;
12+
use crate::errors::{MissingDocCodeExamples, PrivateDocTests};
1213
use crate::html::markdown::{find_testable_code, ErrorCodes, Ignore, LangString};
1314
use crate::visit::DocVisitor;
1415
use crate::visit_ast::inherits_doc_hidden;
@@ -120,24 +121,22 @@ pub(crate) fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item
120121
if tests.found_tests == 0 && cx.tcx.features().rustdoc_missing_doc_code_examples {
121122
if should_have_doc_example(cx, item) {
122123
debug!("reporting error for {:?} (hir_id={:?})", item, hir_id);
123-
let sp = item.attr_span(cx.tcx);
124-
cx.tcx.struct_span_lint_hir(
124+
let span = item.attr_span(cx.tcx);
125+
cx.tcx.emit_spanned_lint(
125126
crate::lint::MISSING_DOC_CODE_EXAMPLES,
126127
hir_id,
127-
sp,
128-
"missing code example in this documentation",
129-
|lint| lint,
128+
span,
129+
MissingDocCodeExamples,
130130
);
131131
}
132132
} else if tests.found_tests > 0
133133
&& !cx.cache.effective_visibilities.is_exported(cx.tcx, item.item_id.expect_def_id())
134134
{
135-
cx.tcx.struct_span_lint_hir(
135+
cx.tcx.emit_spanned_lint(
136136
crate::lint::PRIVATE_DOC_TESTS,
137137
hir_id,
138138
item.attr_span(cx.tcx),
139-
"documentation test in private item",
140-
|lint| lint,
139+
PrivateDocTests,
141140
);
142141
}
143142
}

0 commit comments

Comments
 (0)