rustdoc --test ignores visibility #30094
Labels
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
I-needs-decision
Issue: In need of a decision.
T-dev-tools
Relevant to the dev-tools subteam, which will review and decide on the PR/issue.
T-rustdoc
Relevant to the rustdoc team, which will review and decide on the PR/issue.
Consider the following use case.
I'd expect rustdoc to compile and run doctests only for the public::function since that's the only thing exported from the example crate and thus accessible to rustdoc.
However, this is what I see (actual for current stable (1.4.0) and nightly (1.6, bac2b13) builds):
Rustdoc's intent, as I understand it, is documenting public API. Private items do not show up in docs (unless one explicitly disables the pass that strips them). I believe this should also include doctests.
It's natural to use the items being documented in doctest examples, but such examples for private items would not compile due to obvious reasons. I believe analyzing the code snippets is a bit overkill for rustdoc, but it's pretty reasonable to simply strip any doctests for private items (at least by default), assuming that they contain internal code examples and will not not compile outside of the crate being documented.
Not using documentation comments for private items or marking private code examples with
ignore
avoids the issue, but personally I think that these are poor workarounds. If private doctests are ignored by default then exporting a previously private item (together with its documentation) is simply a matter of adding pub to it (or to its module import in the crate). However, if any of these workarounds are used then one must explicitly convert regular comments to documentation comments and/or removeignore
from doctests in order to get everything right.Some links to (somewhat) related issues:
use
andextern crate
#27104 Have rustdoc document private items, exceptuse
andextern crate
The text was updated successfully, but these errors were encountered: