about summary refs log tree commit diff
diff options
context:
space:
mode:
authoravitex <theavitex@gmail.com>2021-12-28 21:37:08 +1100
committeravitex <theavitex@gmail.com>2021-12-28 21:37:08 +1100
commitb0a1a4469ae3bcab01c999228e0c1e3e9506b43c (patch)
tree142d45b4188e980554e6cae4c3f8dc9317a7735e
parentcc65bf3ded93352fd4693a9c58b84a60721637a6 (diff)
downloadrust-b0a1a4469ae3bcab01c999228e0c1e3e9506b43c.tar.gz
rust-b0a1a4469ae3bcab01c999228e0c1e3e9506b43c.zip
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.
-rw-r--r--src/librustdoc/passes/check_doc_test_visibility.rs2
-rw-r--r--src/test/rustdoc-ui/public-reexported-item-doc-test.rs14
2 files changed, 15 insertions, 1 deletions
diff --git a/src/librustdoc/passes/check_doc_test_visibility.rs b/src/librustdoc/passes/check_doc_test_visibility.rs
index b86ec8abefa..e8f8ff988c1 100644
--- a/src/librustdoc/passes/check_doc_test_visibility.rs
+++ b/src/librustdoc/passes/check_doc_test_visibility.rs
@@ -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,
diff --git a/src/test/rustdoc-ui/public-reexported-item-doc-test.rs b/src/test/rustdoc-ui/public-reexported-item-doc-test.rs
new file mode 100644
index 00000000000..0398975f137
--- /dev/null
+++ b/src/test/rustdoc-ui/public-reexported-item-doc-test.rs
@@ -0,0 +1,14 @@
+// check-pass
+
+#![deny(rustdoc::private_doc_tests)]
+
+mod foo {
+    /// re-exported doc test
+    ///
+    /// ```
+    /// assert!(true);
+    /// ```
+    pub fn bar() {}
+}
+
+pub use foo::bar;