-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Rustdoc links to private types on private items generate a warning #74134
Comments
@rustbot modify labels: T-rustdoc A-intra-doc-links |
Assuming the consensus is that rustdoc shouldn't warn in this case, would an additional check against the --- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
@@ -773,6 +773,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
let hir_id = self.cx.tcx.hir().as_local_hir_id(local);
if !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_id)
+ && (item.visibility == Visibility::Public)
&& !self.cx.render_options.document_private
{
let item_name = item.name.as_deref().unwrap_or("<unknown>"); That certainly gets rid of the warning in my case, but I'm unsure about the other variants of |
That looks reasonable to me. Could you make a PR with that change and a few test cases? |
Wouldn't the check like I changed it then only catch cases like this: struct Private;
pub struct Public {
/// A private field with a [`Private`] type.
pub public: Private,
} But that already triggers
|
@dennis-hamester the link is entirely separate from the type of the field. You could have pub struct Public {
/// See also [`Private`] type
pub public: u32,
} in which case there would be no error but the warning should still be generated. |
@jyn514 Ah, yes of course, thanks for pointing that out :) I'll open a PR then. |
This works around issue #74134 in rustdoc and should be reverted when PR #74147 is merged and available in a nightly. - #74134: rust-lang/rust#74134 - #74147: rust-lang/rust#74147
…jyn514 rustdoc: Allow linking from private items to private types Fixes rust-lang#74134 After PR rust-lang#72771 this would trigger an intra_doc_link_resolution_failure warning when rustdoc is invoked without --document-private-items. Links from private items to private types are however never actually generated in that case and thus shouldn't produce a warning. These links are in fact a very useful tool to document crate internals. Tests are added for all 4 combinations of public/private items and link targets. Test 1 is the case mentioned above and fails without this commit. Tests 2 - 4 passed before already but are added nonetheless to prevent regressions.
…jyn514 rustdoc: Allow linking from private items to private types Fixes rust-lang#74134 After PR rust-lang#72771 this would trigger an intra_doc_link_resolution_failure warning when rustdoc is invoked without --document-private-items. Links from private items to private types are however never actually generated in that case and thus shouldn't produce a warning. These links are in fact a very useful tool to document crate internals. Tests are added for all 4 combinations of public/private items and link targets. Test 1 is the case mentioned above and fails without this commit. Tests 2 - 4 passed before already but are added nonetheless to prevent regressions.
…jyn514 rustdoc: Allow linking from private items to private types Fixes rust-lang#74134 After PR rust-lang#72771 this would trigger an intra_doc_link_resolution_failure warning when rustdoc is invoked without --document-private-items. Links from private items to private types are however never actually generated in that case and thus shouldn't produce a warning. These links are in fact a very useful tool to document crate internals. Tests are added for all 4 combinations of public/private items and link targets. Test 1 is the case mentioned above and fails without this commit. Tests 2 - 4 passed before already but are added nonetheless to prevent regressions.
…jyn514 rustdoc: Allow linking from private items to private types Fixes rust-lang#74134 After PR rust-lang#72771 this would trigger an intra_doc_link_resolution_failure warning when rustdoc is invoked without --document-private-items. Links from private items to private types are however never actually generated in that case and thus shouldn't produce a warning. These links are in fact a very useful tool to document crate internals. Tests are added for all 4 combinations of public/private items and link targets. Test 1 is the case mentioned above and fails without this commit. Tests 2 - 4 passed before already but are added nonetheless to prevent regressions.
…jyn514 rustdoc: Allow linking from private items to private types Fixes rust-lang#74134 After PR rust-lang#72771 this would trigger an intra_doc_link_resolution_failure warning when rustdoc is invoked without --document-private-items. Links from private items to private types are however never actually generated in that case and thus shouldn't produce a warning. These links are in fact a very useful tool to document crate internals. Tests are added for all 4 combinations of public/private items and link targets. Test 1 is the case mentioned above and fails without this commit. Tests 2 - 4 passed before already but are added nonetheless to prevent regressions.
…jyn514 rustdoc: Allow linking from private items to private types Fixes rust-lang#74134 After PR rust-lang#72771 this would trigger an intra_doc_link_resolution_failure warning when rustdoc is invoked without --document-private-items. Links from private items to private types are however never actually generated in that case and thus shouldn't produce a warning. These links are in fact a very useful tool to document crate internals. Tests are added for all 4 combinations of public/private items and link targets. Test 1 is the case mentioned above and fails without this commit. Tests 2 - 4 passed before already but are added nonetheless to prevent regressions.
…jyn514 rustdoc: Allow linking from private items to private types Fixes rust-lang#74134 After PR rust-lang#72771 this would trigger an intra_doc_link_resolution_failure warning when rustdoc is invoked without --document-private-items. Links from private items to private types are however never actually generated in that case and thus shouldn't produce a warning. These links are in fact a very useful tool to document crate internals. Tests are added for all 4 combinations of public/private items and link targets. Test 1 is the case mentioned above and fails without this commit. Tests 2 - 4 passed before already but are added nonetheless to prevent regressions.
With #72771 merged (current nightly, e.g.
1.46.0-nightly (0c03aee8b 2020-07-05)
) , the following code now produces a warning:This triggers
intra_doc_link_resolution_failure
:But rustdoc never actually generates any links to
Private
, because it wasn't run with--document-private-items
. In my opinion it shouldn't emit warning in this case, because documenting the internals can be very useful to contributors or even future me when--document-private-items
is used.There has already been some discussion at the end of #72771, which is where I asked first about whether this change was intentional.
The text was updated successfully, but these errors were encountered: