Skip to content

Commit 4d0b567

Browse files
authored
Rollup merge of #92349 - avitex:fix-rustdoc-private-doc-tests, r=GuillaumeGomez
Fix rustdoc::private_doc_tests lint for public re-exported items Closes #72081 This involves changing the lint to check the access level is exported, rather than public. The [exported access level](https://github.com/rust-lang/rust/blob/e91ad5fc62bdee4a29c18baa5fad2ca42fc91bf4/compiler/rustc_middle/src/middle/privacy.rs#L24) 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.
2 parents 2647ce2 + 992646b commit 4d0b567

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-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,11 @@
1+
#![deny(rustdoc::private_doc_tests)]
2+
3+
mod foo {
4+
/// private doc test
5+
///
6+
/// ```
7+
/// assert!(false);
8+
/// ```
9+
//~^^^^^ ERROR documentation test in private item
10+
pub fn bar() {}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: documentation test in private item
2+
--> $DIR/private-public-item-doc-test.rs:4:5
3+
|
4+
LL | / /// private doc test
5+
LL | | ///
6+
LL | | /// ```
7+
LL | | /// assert!(false);
8+
LL | | /// ```
9+
| |___________^
10+
|
11+
note: the lint level is defined here
12+
--> $DIR/private-public-item-doc-test.rs:1:9
13+
|
14+
LL | #![deny(rustdoc::private_doc_tests)]
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
17+
error: aborting due to previous error
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
3+
#![deny(rustdoc::private_doc_tests)]
4+
5+
pub fn foo() {}
6+
7+
mod private {
8+
/// re-exported doc test
9+
///
10+
/// ```
11+
/// assert!(true);
12+
/// ```
13+
pub fn bar() {}
14+
}
15+
16+
pub use private::bar;

0 commit comments

Comments
 (0)