Skip to content

Fix rustdoc::private_doc_tests lint for public re-exported items #92349

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

Merged
merged 2 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/librustdoc/passes/check_doc_test_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
);
}
} else if tests.found_tests > 0
&& !cx.cache.access_levels.is_public(item.def_id.expect_def_id())
&& !cx.cache.access_levels.is_exported(item.def_id.expect_def_id())
{
cx.tcx.struct_span_lint_hir(
crate::lint::PRIVATE_DOC_TESTS,
Expand Down
11 changes: 11 additions & 0 deletions src/test/rustdoc-ui/private-public-item-doc-test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![deny(rustdoc::private_doc_tests)]

mod foo {
/// private doc test
///
/// ```
/// assert!(false);
/// ```
//~^^^^^ ERROR documentation test in private item
pub fn bar() {}
}
18 changes: 18 additions & 0 deletions src/test/rustdoc-ui/private-public-item-doc-test.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: documentation test in private item
--> $DIR/private-public-item-doc-test.rs:4:5
|
LL | / /// private doc test
LL | | ///
LL | | /// ```
LL | | /// assert!(false);
LL | | /// ```
| |___________^
|
note: the lint level is defined here
--> $DIR/private-public-item-doc-test.rs:1:9
|
LL | #![deny(rustdoc::private_doc_tests)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

16 changes: 16 additions & 0 deletions src/test/rustdoc-ui/public-reexported-item-doc-test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// check-pass

#![deny(rustdoc::private_doc_tests)]

pub fn foo() {}

mod private {
/// re-exported doc test
///
/// ```
/// assert!(true);
/// ```
pub fn bar() {}
}

pub use private::bar;