Skip to content

Commit b0a1a44

Browse files
committed
Fix rustdoc::private_doc_tests lint for public re-exported items
This involves changing the lint to check the access level is exported, rather than public. The exported access level accounts for public items and items accessible to other crates with the help of `pub use` re-exports. The pattern of re-exporting public items from a private module is usage seen in a number of popular crates.
1 parent cc65bf3 commit b0a1a44

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/librustdoc/passes/check_doc_test_visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
131131
);
132132
}
133133
} else if tests.found_tests > 0
134-
&& !cx.cache.access_levels.is_public(item.def_id.expect_def_id())
134+
&& !cx.cache.access_levels.is_exported(item.def_id.expect_def_id())
135135
{
136136
cx.tcx.struct_span_lint_hir(
137137
crate::lint::PRIVATE_DOC_TESTS,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// check-pass
2+
3+
#![deny(rustdoc::private_doc_tests)]
4+
5+
mod foo {
6+
/// re-exported doc test
7+
///
8+
/// ```
9+
/// assert!(true);
10+
/// ```
11+
pub fn bar() {}
12+
}
13+
14+
pub use foo::bar;

0 commit comments

Comments
 (0)